Hello I have a problem.
I am using the below function to create a cookie when there is no one available.
The problem is that when the browser has been closed an opened again, this function creates the Cookie again…even if it is already there.. So everytime the user opens and closes the browser, this cookie gets created and created again..
This is really bad for me. How do I avoid this issue?
What ‘s wrong in my function?
Thanks
<?php
function GenerateTuittingID()
{
$todaydate = date('Ymd');
$time = mktime(date('G'), date('i'), date('s'));
$NowisTime = date('Gis', $time);
$random_numbers = substr(number_format(time() * rand(), 0, '', ''), 0, 10);
$random = $random_numbers . $todaydate;
if (!isset($_COOKIE["tuittingID"])) {
setcookie("tuittingID", $random, mktime(0, 0, 0, 12, 31, 2015));
}
}
?>
1) Open your browser settings, go to
Privacy.2) Click on
Use custom settings for history.3) Make sure the drop down beside
Keep UntilsayThey Expire. If not, update it and press okay.4) Let me know if that solved your problem.
Edit (Just saw your comment)
Set the path and domain on your cookies so they are accessible from the whole site: