bug in coding that i cant figure out...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

bug in coding that i cant figure out...

Post 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.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Where is $_COOKIE['is_login_cookie'] ?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

awww, thanks at least now i dont have to spend hours more stressing over it 8O thanks :D
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Ha - I couldn't even see it :)
Post Reply