March 13, 2012
displaying a message as pop up when my site is open
Question by user1263260
I have a web php web site. I want to show a message on the pop up div when a user browse my site (home page). I need to show the message only the first time with in a browser.
Does anyone know?
Answer by AD7six
There is no php in your question, it is only js and cookies.
The logic you want is:
- Does cookie <name> exist?
- yes
- The user has been to your page/site before
- do nothing
- no
- The user is new
- write cookie <name> with any value
- run your “display message” function
Answer by Starx
Basically, you can do this using two step action, using either sessions
or cookies
- Show the div
- Check if a parameter is previously set
- If not show the div
- Then set a parameter to confirm it is never again, till the browser is closed
Since other answers are focused on cookies, I will give you an example of session.
session_start();
if(!isset($_SESSION['boxshowed']) || !$_SESSION['boxshowed'])) {
echo "<div>to show</div>";
$_SESSION['boxshowed'] = true;
}
Using sessions for this, will show the box again, when the user reopens the site, after completely closing it.