Page 1 of 1

bug in coding that i cant figure out...

Posted: Tue Sep 20, 2005 5:49 am
by mickd
hi, i cant figure out why im getting different values as the output when they should be the same... any help greatly appriciated.

Code: Select all

while($login_cookie_check != '1') {
						$login_cookie_number = mt_rand();
						$login_cookie = md5($login_cookie_number);
						$login_cookie_query = mysql_query("SELECT is_login_cookie FROM accounts WHERE is_login_cookie='$login_cookie'");
							if(mysql_num_rows($login_cookie_query) == '0') {
							$login_cookie_check = '1';
							mysql_query("UPDATE accounts SET is_login_cookie='$login_cookie' WHERE username='" . $_POST['username'] . "'");
							setcookie("is_login_cookie", $login_cookie, time()+3600, "/", ".xxx");
							echo '' . $login_cookie . '<br>' . $_COOKIE['is_login_cookie'] . '';
							}
						}
for $login_cookie and $_COOKIE['is_login_cookie'], their values are different..
(example)
$login_cookie = 49482c7b270b7dcce9b6aa16faf0ef5f
$_COOKIE['is_login_cookie'] = 864deac440ad6789b0d80e66c1309dd0

thanks again for any help.

Posted: Tue Sep 20, 2005 6:50 am
by Grim...
Where is $_COOKIE['is_login_cookie'] ?

Posted: Tue Sep 20, 2005 6:55 am
by Jenk
The problem is the $_COOKIE array is only refreshed upon page reload.

You cannot set the cookie with setcookie() and then immediately access it with $_COOKIE, you must refresh the same page or load a new one to see the update :)

Posted: Tue Sep 20, 2005 7:09 am
by mickd
awww, thanks at least now i dont have to spend hours more stressing over it 8O thanks :D

Posted: Tue Sep 20, 2005 8:33 am
by Grim...
Ha - I couldn't even see it :)