SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    <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:

    PHP Code:
    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; { ?>

    <? ?>

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,129
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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).

    PHP Code:
    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.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •