I use a cookies values into a project to check the visitors entered, firstly, a submit post form exist to enter an email address, after submit, the cookies is set (for next navigation to the current page, should be enter direct to the home page not to the form page if cookies is set), everything goes right, the cookies is set properly , but after navigation to another page the data is lost and no cookies exist!!! is right that cookies should be valid in all pages navigation?? the below figure some codes...
if((!$_COOKIE["tickets"] && $_COOKIE["email_address"]) || (empty($_COOKIE['tickets']) && empty($_COOKIE['email_address']))){
$access_vcount=intval(getCurrentValueAccess())+1;
if(getCurrentValueAccess()==0){$query_vcounts=mysql_query("insert into visitors_counter(counter) VALUES('$access_vcount')");}
else{$query_vcounts=mysql_query("update `visitors_counter` set counter='".$access_vcount."'");}
setcookie("tickets", "accessible", time()+86400);
setcookie("email_address", $email_address, time()+86400);
}
header("Location:".BURL."/".getflink(2,'en'));
The cookies are valid for a one day (should be that). When i try to print the values is cookies in another page , then no result.
Thank you for your suggestions.
When setting a cookie on a page that redirects, the cookie must be set after the call to header('Location: ....');
Such as:
<?php
header('Location: http://www.example.com/');
setcookie('asite', $site, time()+60*60, '/', 'site.com'); ?>
Pasted from comments at http://de3.php.net/manual/en/function.setcookie.php