Possible Duplicate:
How to set cookies for uuid
Hello here’s my site, http://xblgenerator.co.cc . It generates a random id everytime the page is loaded. I want to make a script which saves the output if the id generator for a returning user. For example, if a user visits my site, and gets this id: http://xblgenerator.co.cc/id=12345 , i want the user to see that same id if he refreshes/reloads the page. Maybe this can be done with cookies, but i didn’t have any success with it. Here’s my cookie script which doesnt work,
setcookie('firstvisit', 1);
setcookie('uuid', $rnd_id, time()+368400);
if(isset($_COOKIE['firstvisit']) && isset($_COOKIE['uuid'])) {
// load uuid content
}
Please dont answer that I should use sessions because I want the id to remain the same for the visitor for a month. I don’t want to use databases either. Can somebody tell me what to change in the script above, or what else to do? Thanks.
Make sure you check the cookie value before setting it, otherwise it will be overwritten every time and you won’t know if the user’s browser has already passed in an existing cookie. Other than that, this looks correct.