Only show pop up on load once on visit to site

Hi all,

I am building a little pop up that appears on the front page of a website for a quick survery.

Got it all working fine, but what I want to do is only show that pop up to the current visitor once, so when they come back to the home it doesnt pop up again.

Here is my code that I’m guessing will go in a if statement looking for a session, but not 100% on it:


<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<div style="position:relative; width:100%; height:100%;">
<div style="position:absolute; float:left; top:95px;"><a href="#" onclick="popup('popUpDiv')" style="position:absolute; color:#FFFFFF; font-size:22px;">No</a></div>
<div style="position:absolute; float:left; left:127px; top:95px;"><a href="http://www.surveymonkey.com/s/STZCWNM" target="_blank" style="position:absolute; color:#FFFFFF; font-size:22px;" onclick="popup('popUpDiv')">Yes</a></div>
</div>

I’m thinking of something along this sort of line, but doesnt seem to work:


session_start();


if( $_SESSION['visited'] ){ ?>
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<div style="position:relative; width:100%; height:100%;">
<div style="position:absolute; float:left; top:95px;"><a href="#" onclick="popup('popUpDiv')" style="position:absolute; color:#FFFFFF; font-size:22px;">No</a></div>
<div style="position:absolute; float:left; left:127px; top:95px;"><a href="http://www.surveymonkey.com/s/STZCWNM" target="_blank" style="position:absolute; color:#FFFFFF; font-size:22px;" onclick="popup('popUpDiv')">Yes</a></div>
</div>
<? } else $_SESSION['visited'] = true; { ?>

<? } ?>

First off, your code isn’t quite right (you don’t need an else statement, you need to assign visited when it isn’t set).

session_start(); 


if( !isset($_SESSION['visited']) ){ // visited has never been set, so set it and show the popup
  $_SESSION['visited'] = true; ?> 
<div id="blanket" style="display:none;"></div> 
<div id="popUpDiv" style="display:none;"> 
<div style="position:relative; width:100%; height:100%;"> 
<div style="position:absolute; float:left; top:95px;"><a href="#" onclick="popup('popUpDiv')" style="position:absolute; color:#FFFFFF; font-size:22px;">No</a></div> 
<div style="position:absolute; float:left; left:127px; top:95px;"><a href="http://www.surveymonkey.com/s/STZCWNM" target="_blank" style="position:absolute; color:#FFFFFF; font-size:22px;" onclick="popup('popUpDiv')">Yes</a></div> 
</div> 
<? }?>

Second, this will only NOT show the pop up when the user remains on the same session. Once the session expires, the user will see the popup again. To resolve that, you could use a cookie instead of session, so it can go across sessions (but if the user clears their cookies, or the cookie expires, the popup will appear again.

Right I see, yes I get that…

Thanks for the cookie bit too, but its a very short term survey, maybe even a day, so this will work fine.

Thanks cpradio, take care