Jump to content


Photo

Working with cookies


  • Please log in to reply
1 reply to this topic

#1 global-hans

global-hans
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 July 2006 - 04:45 PM

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;

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

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

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

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

#2 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 06 July 2006 - 05:12 PM

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...........
If you understand everything you know nothing!

http://rcchjr.awardspace.com/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users