Jump to content

Archived

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

global-hans

Working with cookies

Recommended Posts

Dear people,

I just started learning and playing with PHP

For my new website I want to show a message that says "welcome some text". The little script puts up a cookie and if people visit my site for there second time I want it to show something like "back again"

I use the following code to set the cookie;

[code]<?php
$Month = 2592000 + time();
//this adds 30 days to the current time
setcookie(firstvisit, date("F jS - g:i a"), $Month);
?>[/code]

And I use the following to check if there is a cookie and if yes to print the text I want:

[code]<?php
if(isset($_COOKIE['firstvisit']))
{
$last = $_COOKIE['firstvisit'];
echo "Welcome back! <br> You last visited on ". $last;
}
else
{
echo "Welcome to our site!";
}
?>[/code]

This works fine and it really works like I wanted it to work but that's still not enough for me.

At this moment when people refresh the page it shows the second message and that really is something I hate.

I have searched every website but can't find something that can help me out.

Is there a way to tell the script that if the cookie is made today it has to show the first "welcome" message.

Or maybe set a second cookie that checks if the cookie that's made is of today and prints the first message.

Is there anyone who can point me in the right direction?

Thank you all in forward :)

Greetings from Hans

Share this post


Link to post
Share on other sites
Well do you use sessions you could set the sessions id in the cookie and when the session id changes display back again this way if they refresh the Id dont change...........

Share this post


Link to post
Share on other sites

×

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.