global-hans Posted July 6, 2006 Share Posted July 6, 2006 Dear people,I just started learning and playing with PHPFor 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 timesetcookie(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]<?phpif(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 Quote Link to comment https://forums.phpfreaks.com/topic/13866-working-with-cookies/ Share on other sites More sharing options...
jvrothjr Posted July 6, 2006 Share Posted July 6, 2006 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........... Quote Link to comment https://forums.phpfreaks.com/topic/13866-working-with-cookies/#findComment-54008 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.