therealwesfoster Posted January 5, 2008 Share Posted January 5, 2008 Please read the whole thread before replying. Thanks The title of this topic is kind of confusing, but I couldn't think of a perfect one real quick. But check this out. After someone logs in, they get a cookie called ukey and it's value is: 1;77c69387a8c3c1ac68dc654e3652a690 (changing for each user, but i'm using me as example.) The 1 is the user_id, separated from a hashkey with a semi-colon. On every page, I have it explode the cookie like so: $ukey = $_COOKIE['ukey']; list($id, $key) = explode(";",$ukey); I then echo the 2 vars.. it comes out like so: ID = 1 KEY = Why is the KEY left blank when it should be 77c69387a8c3c1ac68dc654e3652a690 Thanks Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 5, 2008 Share Posted January 5, 2008 I don't know much about list() but try this: <?php $ukey = $_COOKIE['ukey']; $arr = explode(";",$ukey); echo $arr[0]."<br />".$arr[1]; ?> Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted January 5, 2008 Author Share Posted January 5, 2008 ^ Thats the same thing. list() is just a way faster way of writing it. But I appreciate the reply Still not solved Quote Link to comment Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 Lets see your setcookie code. Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted January 5, 2008 Author Share Posted January 5, 2008 K. <?php $sql = mysql_query(" SELECT THE USER INFO ") or die("Cant figure out who the heck you are...<br />".mysql_error()); $user = mysql_fetch_array($sql); $key_string = $user['user_id'].";".md5($the_hash_variable); $_SESSION['ukey'] = $key_string; if ( isset($cpost['i_remember']) ) // if we want a cookie set { setcookie("ukey", $key_string); } ?> ^ That sets the cookie Also, i've echo'd the $ukey variable on a page BEFORE exploding it, and it only returns 1.. weird THIS IS WHAT IT IS COOKIE: 1 Username: Wesf90 ID: 1 KEY: THIS IS WHAT IT SHOULD BE COOKIE: 1;77c69387a8c3c1ac68dc654e3652a690 Username: Wesf90 ID: 1 KEY: 77c69387a8c3c1ac68dc654e3652a690 And when i view my cookies, the cookie show the 1;HASH correctly Quote Link to comment Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 This works fine for me <?php $ukey = "1;77c69387a8c3c1ac68dc654e3652a690"; $arr = explode(";",$ukey); echo $arr[0]."<br />".$arr[1]; ?> Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted January 5, 2008 Author Share Posted January 5, 2008 This works fine for me <?php $ukey = "1;77c69387a8c3c1ac68dc654e3652a690"; $arr = explode(";",$ukey); echo $arr[0]."<br />".$arr[1]; ?> Not for me. I don't think it's loading the cookie correctly. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 Well the code above doesn't use a cookie. So if the code above doesn't work, then it's something else. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 You do know that you are not setting a time on your cookie right? So it will expire when you close your browser. Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted January 5, 2008 Author Share Posted January 5, 2008 You do know that you are not setting a time on your cookie right? So it will expire when you close your browser. Thanks, I will set it. BUT, thats not the issue, like I said: "And when i view my cookies, the cookie show the 1;HASH correctly" Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 5, 2008 Share Posted January 5, 2008 Wait, so it shows the string correctly but it doesn't when you explode it? Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted January 5, 2008 Author Share Posted January 5, 2008 No, it's only showing 1 when I echo the cookie. But when I manually view the cookies, it shows 1;77c69387a8c3c1ac68dc654e3652a690 like it's supposed to Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 5, 2008 Share Posted January 5, 2008 What does this echo out? <?php $ukey = $_COOKIE['ukey']; echo $ukey; $arr = explode(";",$ukey); /*echo $arr[0]."<br />".$arr[1];*/ ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 Try using another delimeter instead Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted January 5, 2008 Author Share Posted January 5, 2008 All I can figure is it is a browser problem.. because It's working now all of a sudden.. I don't get it.. I'm using firefox... weird ??? Anyways, thanks for all the replies.. solved for now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.