Click here to Skip to main content
13,006,180 members (68,090 online)
Rate this:
Please Sign up or sign in to vote.
In MVC Framework.

I have a JavaScript that set the cookie value when I press a link button click. here is the code of my JavaScript:
 <script type="text/javascript" >
    (function() {
        document.getElementById("mylink").onclick = function() { 
            var the_cookie = "video=video;" ; 
            document.cookie = the_cookie;
            //location = 'http://localhost/nproject/index.php?c=files&a=index&active_project=2&1369320566'; 
            //var video = document.getElementById("mylink").value;

And my link in local pc is :

And I don't understand anything about this link as I am a new comer in MVC framework. I have just write this JavaScript in list_files.php. And my link button is on index.php. In index.php I have just add the link as like this:
echo '<div><a id = "mylink" value ="video"'; 
echo 'href="';
echo '" >Video</a> </div>';

Because, the end of the index.php is :
<?php $this->includeTemplate(get_template_path('list_files', 'files')) ?>

As it is loading my list_files.php.
And when I am clicking on the link its alerting me "undefned". And I have also write my PHP code in list_files.php for getting cookies value in php variable for my another checking.
PHP variable set by Cookie:
<?php if(isset($_COOKIE["video"]))
         { $value = $_COOKIE["video"];
           echo $value;

As I am getting the result undefined so, I become confuse to do later jobs. Please help me.
Posted 23-May-13 5:56am
Mohibur Rashid 23-May-13 20:50pm
you are alerting alert(document.cookie.value);

but you were suppose to alert alert(document.cookie);

you won't get undefined

run this example, it might make sense
<? print_r($_COOKIE);
<form >
<input type=submit value='crack' önclick='document.cookie="thedata=value"'>
</form >

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170628.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100