PHP array from cookie info: only shows up after you refresh the page? -


so i'm trying return items array that's made out of user inputted info cookies, , works fine, except when first visit page previous page, nothing shows up, , have refresh see array. have no idea why wouldn't show first time around? (there javascript alerts in there work fine. it's array i'm having trouble with.) here's code, advice great, thanks:

$usergatsby = $_cookie['gatq']; $usercatcher = $_cookie['catcherq']; $userwaves = $_cookie['wavesq']; $userstranger = $_cookie['strangerq']; $userulysses = $_cookie['ulyssesq']; $userpride = $_cookie['prideq']; $usermockingbird = $_cookie['mockingbirdq']; $userroad = $_cookie['roadq'];   if ($_cookie['fname'] == null or $_cookie['lname'] == null or $_cookie['address'] == null or $_cookie['city'] == null or $_cookie['state'] == null or $_cookie['zip'] == null or $_cookie['email'] == null) {echo "<script language='javascript'> window.alert('you left information on personal info page! redirected.');     window.location.href='personal.php';</script>"; }  else     {          if ($_cookie['gatq'] == null &&         $_cookie['catcherq'] == null &&         $_cookie['wavesq'] == null &&         $_cookie['strangerq'] == null &&         $_cookie['ulyssesq'] == null &&         $_cookie['prideq'] == null &&         $_cookie['mockingbirdq'] == null &&         $_cookie['roadq'] == null)              {echo "<script language='javascript'>                 window.alert('you don't have in shopping cart! redirected.');                 window.location.href='inventory.php';</script>";             }                      else                         {$productarray = array($usergatsby=>'the great gatsby <img src="gatsby.jpg">',              $usercatcher=>'catcher in rye <img src="catcher.jpg">',               $userwaves=>'the waves <img src="waves.jpg">',               $userstranger=>'the stranger <img src="stranger.jpg">',               $userulysses=>'ulysses <img src="ulysses.jpg">',               $userpride=>'pride , prejudice <img src="pride.jpg">',               $usermockingbird=>'to kill mockingbird <img src="mockingbird.jpg">',               $userroad=>'on road <img src="ontheroad.jpg">'               );                              asort($productarray);                             foreach ($productarray $book=>$info)                                         {if ($book > 0)                                                 {echo "quantity: " . $book . " " . $info . "<br>";}                                         }                           }       }   ?> 

you can't read value of cookie until new page request made. because value of cookie data sent page request. isn't available access value until after set , new page request made.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -