Reputation: 11
How can a save a cookie using php for every visitor on my site? My website also has a unique ID generator. I want to know how to make the id stay the same using cookies
Upvotes: 1
Views: 1174
Reputation: 5149
You could check W3Schools' PHP guide, it has a lot of useful code snippets to do with cookies.
Depending what you are doing, you may also want to check out Sessions.
Upvotes: -1
Reputation: 4351
You can use the setcookie() function to store a cookie.
Example Code
//Check if cookie exists
if (isset($_COOKIE['uid'])) {
//Get UID from cookie
$uid = $_COOKIE['uid'];
} else {
//Generate UID
$uid = uniqid();
//Store in cookie
setcookie('uid',$uid);
}
Upvotes: 8