pedro84 Posted March 6, 2008 Share Posted March 6, 2008 Hi there, I got login script. I wanted to add some feature to remember user's login for some time. But first, some code. Function auto_login_cookie sends cookie if user want to, function auto_login checks the cookies. In the cookies only hashed username and user's uniqid are stored. function auto_login_cookie (){ if (isset($_POST['staylogged']) && $_POST['staylogged'] == 1) $username = $_SESSION['username']; $query = mysql_query("SELECT uniqid, username FROM users WHERE username = '$username' limit 1") or die ('Error'); $r = mysql_fetch_assoc($query); setcookie("bbuniqueidhash", $r['uniqid'], time() + 30 * 86400); setcookie("bbusernamehash", md5($r['username']), time() + 30 * 86400, "/", ".traderslists.com", 1); } function auto_login (){ $username = $_SESSION['username']; $query = mysql_query("SELECT uniqid, username FROM users WHERE username = '$username' limit 1") or die ('Error'); $r = mysql_fetch_assoc($query); if (isset($_COOKIE['bbuniqueidhash']) && $_COOKIE['bbuniqueidhash'] == $r['uniqid'] AND (isset($_COOKIE['bbusernamehash']) && $_COOKIE['bbusernamehash'] == md5($r['username']))){ return true; } else { return false; } } Ok. This functions checks if user is logged: function is_authed() { if (isset($_SESSION['username']) && (md5($_SESSION['username']) == $_SESSION['encrypted_name'])) { return true; } else { return false; } } and I check it this way: if (!is_authed()) { die ('You are not permitted to view this page, <a href="login.php">click here</a> to login.'); } There're some problems with that script. First of all, when I'm comparing cookies with the data in database everything is ok. Cookies are sending correctly if I want to, and data are equal with the data in database. But...how to call that function? I tried: auto_login(); if (!is_authed()) { die ('You are not permitted to view this page, <a href="login.php">click here</a> to login.'); } but it does not work. I tried to make it many ways withou any positive result. Have you got any ideas and suggestions? Second case, I tested everything on my local server, but when I tried to debug on the webserver, cookies are not sending:( What did I do wrong? Need help:) Later, Pedro Link to comment https://forums.phpfreaks.com/topic/94690-problems-with-functions-and-cookies/ Share on other sites More sharing options...
pedro84 Posted March 6, 2008 Author Share Posted March 6, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/94690-problems-with-functions-and-cookies/#findComment-484854 Share on other sites More sharing options...
pedro84 Posted March 6, 2008 Author Share Posted March 6, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/94690-problems-with-functions-and-cookies/#findComment-485422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.