smguy Posted October 24, 2008 Share Posted October 24, 2008 Hey everyone. I'm a pretty new PHP coder and I've been working on a little pet project, a game while teaching myself PHP from online tutorials. I have xampp at home and I use the school web servers while I'm at the lab there and my code has worked perfectly until about two days ago, when it suddenly stopped retrieving my cookies. <?php $maxhp = $_COOKIE['maxhp']; $hp = $_COOKIE['hp']; $exp = $_COOKIE['exp']; $race = $_COOKIE['race']; $gold = $_COOKIE['gold']; $str = $_COOKIE['str']; $agi = $_COOKIE['agi']; $vit = $_COOKIE['vit']; $luk = $_COOKIE['luk']; function head() { echo '<head> <title>Blah</title> <style> body{ background-color:#000000; color:#FFFFFF; font-family:"lucida console"; font-weight:bolder; } </style> </head> <body>'; echo $race."<br />HP: ".$hp."/".$maxhp."<br />Str: ".$str."<br />Agi: ".$agi."<br />Vit: ".$vit."<br />Luk: ".$luk."<br />".$gold." gp, ".$exp." exp."; }; ?> That's the code for my maincore.php file that I use as a header for most pages. Here's a sample of one of the pages that uses maincore.php: <?php require_once ("../maincore.php"); head(); echo"<br /><br />What would you like to do in the desert?<br />"; echo '<form method="post" action="desertchoice.php"> <select name="desertchoice"> <option value="fight">Look for a Fight</option> <option value="town">Travel to town</option> <option value="forest">Go to the forest</option> </select><br /> <input type="submit" value="Choose" /> </form>'; echo '</body> </html>'; ?> Before you ask, it's not a problem with setting the cookies themselves, as both the browser at home and the browser at the school show all of the cookies with the correct names and correct values in the cookie cache. I would really appreciate it if someone could tell me what's wrong. Thanks! Link to comment https://forums.phpfreaks.com/topic/129900-cookies-not-retrieving/ Share on other sites More sharing options...
valtido Posted October 24, 2008 Share Posted October 24, 2008 i dont see where you have given the cookies a value in the first place. from the code you ahve posted it just looks like you are retrieving cookies which are not previously set. unless you have another file or something. Link to comment https://forums.phpfreaks.com/topic/129900-cookies-not-retrieving/#findComment-673598 Share on other sites More sharing options...
prexep Posted October 24, 2008 Share Posted October 24, 2008 Variables aren't global and can't be called in the function. Try putting it in the function? Link to comment https://forums.phpfreaks.com/topic/129900-cookies-not-retrieving/#findComment-673617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.