PHP Bug

Discussion in 'PHP' started by GoURL.Biz, Jan 18, 2007.

  1. #1
    For me to better explain this you will need to go to my site GoURL.Biz and click "Forwarding Options". Here you will be able to enable and disable the preview feature.

    When you press enable, it creates a cookie to store that setting, just like when you press disable. The cookie is called towards the end of the script to determine which of the drop-down menus is "selected". For example, if you have preview enabled, when you load the page, it should automatically show "enabled".

    However when you visit that page and change the variable (lets say to from disable to enable), when the page loads again it shows the old setting. If you re-visit that page (NOT refresh), it shows the correct setting.

    I want it to show the correct setting immediately after it has been changed.

    The very first thing in that script is the setting of the cookies depending on which option you have chosen. Later down the script, it calls the cookie.

    Are you allowed to set a cookie, then call it within the same script ?
     
    GoURL.Biz, Jan 18, 2007 IP
  2. solidphp

    solidphp Peon

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No. The cookie won't be available until the next page refresh.
     
    solidphp, Jan 18, 2007 IP
  3. KalvinB

    KalvinB Peon

    Messages:
    2,787
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Set the cookie to the value but also store the value in a variable that your script can use. When you need to check the cookie see if the cookie value is set and if it is use that otherwise use the variable that holds the value that is stored in the cookie.

    
    $setting = 1;
    
    cookie = $setting;
    
    if(isset(cookie)) $setting = cookie;
    
    if($setting) blah else other blah
    
    
    Code (markup):
     
    KalvinB, Jan 18, 2007 IP
    debunked likes this.
  4. GoURL.Biz

    GoURL.Biz Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yer, didn't think so.

    Try now, it working correctly for you ?
     
    GoURL.Biz, Jan 19, 2007 IP