Vivid Lust Posted May 4, 2011 Share Posted May 4, 2011 Hi all, I'm struggling with a program I'm trying to write with cookies, so any help would be very much appreciated!! What I'm wanting to do is when someone visits my site, I want to display content until the end of the day, and once the days up it disappears forever/until the cookies are deleted. Could someone help me with this? Thanks lots in advance, Jake Quote Link to comment https://forums.phpfreaks.com/topic/235496-cookie-help/ Share on other sites More sharing options...
priti Posted May 4, 2011 Share Posted May 4, 2011 explore setcookie() function in php Quote Link to comment https://forums.phpfreaks.com/topic/235496-cookie-help/#findComment-1210352 Share on other sites More sharing options...
cyberRobot Posted May 4, 2011 Share Posted May 4, 2011 What do you mean by "disappears forever", are you looking to delete the data altogether once the cookie expires? Or are you just wanting the content to be unavailable to the user post-cookie? Quote Link to comment https://forums.phpfreaks.com/topic/235496-cookie-help/#findComment-1210353 Share on other sites More sharing options...
Vivid Lust Posted May 5, 2011 Author Share Posted May 5, 2011 I only want certain content to appear on a page until midnight the first time they visit, after that it never appears again until the cookie is deleted. Quote Link to comment https://forums.phpfreaks.com/topic/235496-cookie-help/#findComment-1210805 Share on other sites More sharing options...
nzol Posted May 5, 2011 Share Posted May 5, 2011 You may want something like this: $midnighthour = "23"; $midnightmin = "59"; $hour = date("G"); $hoursminutes = $hour*60; $minutes = date("i"); $minutesfrommidnighta = $hoursminutes+$minutes; $minutesfrommidnightb = 1440-$minutesfrommidnighta; $username = $_GET['username']; $getcookie = $_COOKIE['user']; if($getcookie==0) { $createcookie = setcookie("user",$username,time()+$minutesfrommidnightb); } else { if($getcookie==$username) { // the code you want to execute if the user cookie is there } else { // the code you want to execute if the user cookie does not exist. } } Quote Link to comment https://forums.phpfreaks.com/topic/235496-cookie-help/#findComment-1210818 Share on other sites More sharing options...
cyberRobot Posted May 5, 2011 Share Posted May 5, 2011 I only want certain content to appear on a page until midnight the first time they visit, after that it never appears again until the cookie is deleted. You could create a cookie that stores the timestamp of their first visit. Using PHP, you could then compare the cookie timestamp to your midnight deadline. If the cookie timestamp is less than the midnight deadline timestamp, show them the data. mktime() could be used to create the midnight deadline timestamp: http://php.net/manual/en/function.mktime.php time() could be used to get the initial timestamp of the cookie: http://php.net/manual/en/function.time.php setcookie() could be used to create the cookie: http://php.net/manual/en/function.setcookie.php $_COOKIE could be used to read the cookie: http://php.net/manual/en/reserved.variables.cookies.php Quote Link to comment https://forums.phpfreaks.com/topic/235496-cookie-help/#findComment-1210880 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.