Need Help put Expire Cookies to this command ? Please Help

Discussion in 'Programming' started by A.G, Apr 5, 2012.

  1. #1
    Hello,

    I have simple div windows appear when the visitor enter the page, i just want to put an expiring cookie so the visitor see this message window only once even if he refresh the page, and the cookie should expire after an hour or half hour

    here the page and the code in the source
    http://www.mp3music.tv/demo.htm

    so anyone could help to make this window appear only once to each visitor until his cookie expire
    thanks
     
    Solved! View solution.
    A.G, Apr 5, 2012 IP
  2. A.G

    A.G Well-Known Member

    Messages:
    2,510
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    150
    #2
    come on guys nobody knows, i saw expiring 24hour cookie on a popup code but i couldn't figure out how to use it on my code
     
    A.G, Apr 6, 2012 IP
  3. mikeweller

    mikeweller Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    3
    Trophy Points:
    0
    #3
    You need to do this in PHP, so you would have to move your HTML into a PHP file.

    At the top of the PHP file, create the cookie like this:
    <?php setcookie("showdiv", "x", 60*60*24); ?>

    Identify the HTML code that should only be displayed once a day.

    Right before that piece of HTML, add this:

    <?php if(!isset($_COOKIE["showdiv"])) { ?>

    And right after that piece of HTML, add this:

    <?php } ?>
     
    mikeweller, Apr 14, 2012 IP
  4. A.G

    A.G Well-Known Member

    Messages:
    2,510
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    150
    #4
    hi, thanks for help, i did change demo.htm to demo.php and put this code on the top of the page "<?php setcookie("showdiv", "x", 60*60*24); ?>"

    then i locate the div html section and i added this code before it "<?php if(!isset($_COOKIE["showdiv"])) { ?>"
    and then at the end of the </div> section i put this "<?php } ?> "

    but still message appear in every refresh, did i make any mistake
     
    A.G, Apr 20, 2012 IP
  5. #5
    Sorry, I made a mistake...

    Change this:

    60*60*24

    to this:

    time() +
    60*60*24

     
    mikeweller, Apr 20, 2012 IP
  6. A.G

    A.G Well-Known Member

    Messages:
    2,510
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    150
    #6
    thanks man you are awesome
     
    A.G, Apr 21, 2012 IP