clown[NOR] Posted April 14, 2007 Share Posted April 14, 2007 I'm tearing every single hear off my head now... i just cant get this set cookie to work... does anyone have any clue why it wont work? both $tmpUser & $tmpPass contains value...have double checked that... <?php include('config/db.php'); $tmpUser = trim($_POST['username']); $tmpPass = trim($_POST['password']); setcookie("username", $tmpUser, time()+24*3600*12); if (!mysql_connect($dbHost, $dbUser, $dbPass)) { die("Unable to connect to DB"); } if (!mysql_select_db($dbName)) { die("Unable to select to DB"); } $query = "SELECT * FROM users WHERE username = '" . mysql_real_escape_string($tmpUser) . "'"; $result = mysql_query($query); if (!$result) { die("Could not run query from DB"); } while ($dbField = mysql_fetch_assoc($result)) { $chkPass = $dbField['password']; } if ($tmpPass != $chkPass) { echo "Wrong password"; #header("Location: index.php"); #exit; } else { echo "You have been signed in as: ".$_COOKIE['username']; #$query = "UPDATE users SET status = 'ONLINE' WHERE username = '" . mysql_real_escape_string($_COOKIE['username']) . "' AND status = 'OFFLINE'"; #if (!mysql_query($query)) { die("Could not run query from DB"); } #header("Location: index.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/46989-solved-darn-setcookie-wont-work/ Share on other sites More sharing options...
clown[NOR] Posted April 14, 2007 Author Share Posted April 14, 2007 ok... it's setting now... but only if I click the login button 2 times...hehe... =) Link to comment https://forums.phpfreaks.com/topic/46989-solved-darn-setcookie-wont-work/#findComment-229130 Share on other sites More sharing options...
PC Nerd Posted April 14, 2007 Share Posted April 14, 2007 um, its prolly setting but you cant veiw cookie contents on the page that its set, ie, refresh and itll work also, its header information, so your database connection isoutput, thats prolly why um, i think i use itm but am not sure look at output buffereing, start_ob(), fluch_ob () um, searhc some of my previously "cookies" or "lgin system" sort of stuff started by me theres a nice explaination there gdlk Link to comment https://forums.phpfreaks.com/topic/46989-solved-darn-setcookie-wont-work/#findComment-229147 Share on other sites More sharing options...
clown[NOR] Posted April 14, 2007 Author Share Posted April 14, 2007 i figured it out... it must have been something about the setcookie .. what I did was: i changed this line: "UPDATE users SET status = 'ONLINE' WHERE username = '" . mysql_real_escape_string($_COOKIE['username']) . "' AND status = 'OFFLINE'"; to this "UPDATE users SET status = 'ONLINE' WHERE username = '" . mysql_real_escape_string($tmpUser) . "' AND status = 'OFFLINE'"; i posted the solution to... incase somebody else is facing the same issue.... Link to comment https://forums.phpfreaks.com/topic/46989-solved-darn-setcookie-wont-work/#findComment-229218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.