PHP Cookies Help

Discussion in 'PHP' started by homemadejam, Dec 13, 2008.

  1. #1
    So, all this is new to me... but I am almost certain that I have this right.. however, it's not working

    
    <?php
    $Month = 2592000 + time(); //this adds 30 days to the current time
    setcookie(warning, 1 , $Month); // sets cookie with name warning, value of 1, and expiry date
    ?>
    
    <?php
    if ($HTTP_cookie_VARS[warning] == "1")
    {
    echo "document.write('<javascript>showPopUp();</javascript>')"
    }
    else
    {
     /*do nothing...*/
    }
    ?>
    PHP:
    
    <script>showPopUp() {
    tb_show('WARNING!', '{$mybb->settings['bburl']}/warning.html?width=250&height=300&modal=true');
    }</script>
    Code (markup):
    Can anyone see where I am going wrong here?
    What I want to happen is the the JavaScript to run only if in the cookie there is a value of 1.
    (as the javascript is a warning pop up box, telling users they have to be 18+ to enter)

    Thanks,
    Jam
     
    homemadejam, Dec 13, 2008 IP
  2. Divisive Cottonwood

    Divisive Cottonwood Peon

    Messages:
    1,674
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maybe...

    
    <?php
    $Month = 2592000 + time(); //this adds 30 days to the current time
    setcookie(warning, 1 , $Month); // sets cookie with name warning, value of 1, and expiry date
    ?>
    
    <?php
    if ($HTTP_cookie_VARS[warning] == "1") { 
    	echo "document.write('<javascript>showPopUp();</javascript>')";
    } else {
    echo null; 
    }
    ?>
    Code (markup):
     
    Divisive Cottonwood, Dec 13, 2008 IP
  3. homemadejam

    homemadejam Well-Known Member

    Messages:
    143
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    145
    #3
    Thanks for your reply...
    When I use the code that you provided, nothing still happen,and get this displaying on the screen:

    So take it that there is something wrong with the echo statement?

    Thanks,
    Jam
     
    homemadejam, Dec 14, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    try this

    
    <?php
    $Month = 2592000 + time(); //this adds 30 days to the current time
    setcookie('warning', 1 , $Month); // sets cookie with name warning, value of 1, and expiry date
    ?>
    
    <?php
    if ($HTTP_cookie_VARS['warning'] == "1")
    {
    echo "document.write('<script type=\"text/javascript\">showPopUp();</script>')";
    }
    else
    {
     /*do nothing...*/
    }
    ?>
    
    PHP:
     
    ads2help, Dec 14, 2008 IP
  5. jinxin

    jinxin Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    echo "<script>showPopUp();</script>)"
     
    jinxin, Dec 14, 2008 IP