Heya,
So I need to display a message to first time visitors (even if they close their browser and come back a day later) but I'm not sure how to do this and I have scoured Google for the solution to no avail. Can someone help? Thanks!
Showing message on first visit only, need help...
Moderator: General Moderators
-
WithHisStripes
- Forum Contributor
- Posts: 131
- Joined: Tue Sep 13, 2005 7:48 pm
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Showing message on first visit only, need help...
Set a cookie with an infinite or very long lifetime and then check for this cookie.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
WithHisStripes
- Forum Contributor
- Posts: 131
- Joined: Tue Sep 13, 2005 7:48 pm
Re: Showing message on first visit only, need help...
I don't see how that solves my problem. Can you elaborate a little and provided an example? Thanks!
Re: Showing message on first visit only, need help...
It's highly advisable that you look up a cookie tutorial. That will answer all of your questions and it's full of examples.
In a nutshell though, a cookie resides on the user's computer. When the user visits your page, your site checks for the existence of the cookie. If it's there, the message does not display. If it's not there, the message you want displayed the first time appears. Problem solved.
In a nutshell though, a cookie resides on the user's computer. When the user visits your page, your site checks for the existence of the cookie. If it's there, the message does not display. If it's not there, the message you want displayed the first time appears. Problem solved.
-
WithHisStripes
- Forum Contributor
- Posts: 131
- Joined: Tue Sep 13, 2005 7:48 pm
Re: Showing message on first visit only, need help...
Hey Jake, thanks for the reply. I probably should have mentioned that I've followed several cookie tutorials (JS and PHP) thus far and haven't been able to figure it out. So if someone can give me an example now that you've explained it I would really appreciate it because I'm stuck. Thanks!
Re: Showing message on first visit only, need help...
Here's an example, it should work.
Code: Select all
<?php
start_session();
set_cookie('myCookie','visitCheck', time()+60*60*24*30*12, '/','.yourdomain.com',false, true); //cookie set to one year
//here's the test
If (!isset($_COOKIE['myCookie'])) { //if the cookie is NOT set, then display the block of code. if it is set, you don't need to do anything.
//display something
}
?>