Jump to content

cookie help

Vivid Lust

Recommended Posts

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,



Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:



time() could be used to get the initial timestamp of the cookie:



setcookie() could be used to create the cookie:



$_COOKIE could be used to read the cookie:



Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.