danieljgraham Posted September 4, 2010 Share Posted September 4, 2010 Im trying to use the following code; if($login_Remember) { /* Check if Remember Me was set */ setcookie('login_ID', $row['ID'], time()+3600 * 24 * 30); setcookie('login_Name', $row['Name'], time()+3600 * 24 * 30); setcookie('login_Access', $row['Value'], time()+3600 * 24 * 30); } header("Location: index.php"); When i try to use it, the only cookie thats registered is the bottom on "login_Access". None of the others are. I have tried everything but nothings working. I dont get any error messages. Using PHP v5.3.3 on IIS Please help. Thanks [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
freeloader Posted September 4, 2010 Share Posted September 4, 2010 A basic remember me code right? There are probably tons of good examples on the net, here are some discussions on this board: http://www.phpfreaks.com/forums/index.php/topic,307051.0/topicseen.html In this topic I've posted a remember me which I've written myself: http://www.phpfreaks.com/forums/index.php/topic,307065.0.html Quote Link to comment Share on other sites More sharing options...
danieljgraham Posted September 4, 2010 Author Share Posted September 4, 2010 Thank you for your help, heres what i came up with, and appears to be really secure. if($login_Remember) { /* Check if Remember Me was set */ $sql = "UPDATE Users SET Session = '$session_id' WHERE id = " . $row['ID']; mysql_query($sql); setcookie('PDMS_SESSION', $session_id, time()+3600 * 24 * 30); } Then on every page i do a Session check, if that ok then it just returns true. Otherwise it'll check the cookie and and do an SQL query for that cookie Public function doLoginCheck () { if(isset($_SESSION['login_ID'])) { return true; } if(isset($_COOKIE['PDMS_SESSION'])) { $query = sprintf("SELECT users.* , user_groups.Value FROM users LEFT JOIN user_groups ON (users.Access = user_groups.ID) WHERE users.Session = '%s' LIMIT 0,1", $_COOKIE['PDMS_SESSION']); $result = mysql_query($query) or die('Error, Cookie check failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $_SESSION['login_ID'] = $row['ID']; $_SESSION['login_Name'] = $row['Name']; $_SESSION['login_Access'] = $row['Value']; return true; } header("Location: login.php"); } Seems to do the trick. Thanks for your help. Dan Quote Link to comment Share on other sites More sharing options...
freeloader Posted September 4, 2010 Share Posted September 4, 2010 Should do the trick 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.