Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
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;
            alert(document.cookie.value);
            
        };
    })();
</script>


And my link in local pc is :
http://localhost/nproject/index.php?c=files&a=index&active_project=1&1369323644[^]

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:
PHP
echo '<div><a id = "mylink" value ="video"'; 
echo 'href="';
get_url('files');
echo '" >Video</a> </div>';

Because, the end of the index.php is :
PHP
<?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
<?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
Comments
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);
?>
<script>
</script>
<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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900