Irresistable Posted November 14, 2009 Share Posted November 14, 2009 I have made a checkbox, to keep users logged in for a certain amount of time. However.. I put if checkbox == check { set cookie ID Username; set cookie ID Password } Also, I checked for the cookie further up, and if cookie is there, it logs in. In my case.. I'm not sure if it sets the cookie, or its not reading the cookie, or what? Here is the PHP code for the login form. <?php session_start(); if($_SESSION['s_logged_n'] == 'true'){ header("location: index.php"); } include 'config.php'; //Checks if there is a login cookie if(isset($_COOKIE['ID_username'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_username']; $pass = $_COOKIE['Key_password']; $check = mysql_query("SELECT * FROM Users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: member.php?$username"); } } } if(isset($_POST['login'])) { $username = trim(addslashes($_POST['username'])); $password = md5(trim($_POST['password'])); $query = mysql_query("SELECT * FROM Users WHERE Username = '$username' AND Password = '$password' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($query); // now we check if they are activated if(mysql_num_rows($query) > 0) { if($row['Activated'] > 0) { $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['Name']; if(isset($_POST['keep']) == checked) { $time = time() + 60*60*24*1000; setcookie(ID_username, $username, $time); setcookie(Key_password, $password, $time); } header("Location: member.php?$username"); } else{ $error['notactivated']=' <p>Sorry, you must activate your account first. Please check your email for the email.</p> '; }; }else {$error['problemwithlogin']=' <p>There was an error processing your login, it appears that your username and/or password was incorrect. Please try again.</p> '; }; }; ?> Also for a quick note, once this gets working, how would I use it to set it as logged in. EG: If I came back to the website 2 days later, and instead of going to login.php, i go to the homepage, how will I set it so that it recognises me as logged in there too. Whats wrong with the code? thanks. Quote Link to comment Share on other sites More sharing options...
Irresistable Posted November 14, 2009 Author Share Posted November 14, 2009 False alarm, I did it. Checked to see if Username and Password had capitals letters, and they didn't. 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.