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", TRUE, time()+3600);
}
}
?>
<?php check_cookie(); ?>
Can anyone see where I am going wrong here?
Thank you