Thread: Resolved Checking for a cookie?
View Single Post
Old 11-30-2012, 02:10 PM   PM User | #1
Oatley
New Coder

 
Join Date: Sep 2012
Posts: 70
Thanks: 56
Thanked 0 Times in 0 Posts
Oatley is an unknown quantity at this point
Checking for a cookie?

Hello, I'm stuck on something with a cookie and must be missing something obvious, but I can't see what.

In my script I want to load a page and

1 - Check if a cookie exists
2- If it does not launch a JavaScript function called myFunction and set a cookie

Now, the first time I launch the page the function shows (as there is no cookie in my browser) which is great but on subsequent loads when I refresh the page it should not show as a cookie should be created

PHP Code:
<?php
function check_cookie() {
If(
$_COOKIE['test'] != TRUE) {
?>
<script type="text/javascript">
myFunction();
</script> 
<?php
setcookie
("test"TRUEtime()+3600);
}
}
?>
<?php check_cookie
(); ?>
Can anyone see where I am going wrong here?

Thank you

Last edited by Oatley; 11-30-2012 at 05:46 PM..
Oatley is offline   Reply With Quote