How to set cookie to the visitor so pop only gets shown once ?

Discussion in 'PHP' started by poseidon, Sep 29, 2007.

  1. #1
    I am working on a popup script which gets shown when the user leaves the page. The problem is, the user keep on getting shown that page whenever he leaves page Everytime which I dont' want.

    I just want the pop up to be shown to the first time visitor only. That's it. This can be easily done with PHP but I am just wondering what's the best way of doing it ? Is putting such cookie function on footer file a good idea, since it will called everytime when the page gets load, increasing the loadtime of the page ?

    Cheers
     
    poseidon, Sep 29, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    if (!isset($_COOKIE['popup']))
    {
        setcookie('popup', 1, strtotime('+1 Day'));
    
        ?>
        
        pop up code here
    
        <?php
    }
    
    PHP:
     
    nico_swd, Sep 29, 2007 IP