I want to save a cookie for a visitor. I use the code below but it seems it won’t work for me. Please guide me where I am wrong
<script type="text/javascript">
if(!isset($_COOKIE['visited_alreadyxxx']))
{
setcookie('visited_alreadyxxx' , 'true' , time()+60*60*24*7*365);
alert("hi");
}
</script>
Edit : sorry for above code , does below code work correctly ?
<?php
if(!isset($_COOKIE['visited_alreadyxxx']))
{
setcookie('visited_alreadyxxx' , 'true' , time()+60*60*24*7*365);
?>
<script>alert("hi");</script>
<?
}
?>
I don’t think you can access cookies like that. It appears to be PHP, mixed with Javascript.
The Javascript interpreter doesn’t know how to parse PHP, and will fail to execute.