graham23s Posted September 29, 2008 Share Posted September 29, 2008 Hi Guys, When i check "remember my login" on the login.php page i have set a cookie but it doesn't seem to remember you once the browser closes! code: login.php <?php // include the database connection // include("inc/inc-dbconnection.php"); include("inc/inc-online.php"); include("inc/inc-header.php"); include("inc/inc-navigation.php"); ?> <?php // standard header // print("<div class=\"subheader\"><div id=\"title\">Home > <span class=\"blue\">Login to your account</span></div>You can update your personal details and view orders in here. forgot your password? no worries recover it <a class=\"smart_links\" href=\"recover-password.php\">here</a>.</div>"); // check to see if the session exists // if(isset($_SESSION['id'])) { print("<div id=\"shopping_login_error\">You are already logged in.</div>"); include("inc/inc-footer.php"); exit; } // login box // print('<form action="login-check.php" method="POST" onSubmit="return login_check()" name="login_form" />'); print("<table border=\"0\" cellpadding=\"5\" cellspacing=\"1\" class=\"tbl_login\">\n"); print("<tr>\n"); print("<td colspan=\"2\" align=\"left\" class=\"c3\"><b>Login</b></td>\n"); print("</tr>\n"); print("<tr class=\"c5\">\n"); print("<td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td><td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td>\n"); print("</tr>\n"); print("<tr class=\"c1\">\n"); print("<td align=\"left\" class=\"font_for_forms\">E-Mail:</td><td class=\"class=\"font_for_forms\" align=left><input type=\"text\" size=\"40\" name=\"email\" /></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td align=\"left\" class=\"font_for_forms\">Password:</td><td class=\"class=\"font_for_forms\" align=left><input type=\"password\" size=\"40\" name=\"password\" /></td>\n"); print("</tr>\n"); print("<tr class=\"c1\">\n"); print("<td align=\"right\" class=\"font_for_forms\"> </td><td class=\"font_for_forms\" align=\"left\"><input type=\"checkbox\" name=\"remember\" value='yes'>Remember me next time i log in.</td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td colspan=\"2\" align=\"right\" class=\"font_for_forms\"><input type=\"submit\" name=\"submit\" value=\"Login\"></td>"); print("</tr>\n"); print("</table>\n"); print("</form>\n"); print("<br />"); // just a little note to remember them! print("<span class=\"msg_remember\">You must be logged in to place orders. you can register an account <a class=\"smart_links\" href=\"register.php\">here</a>.</span>"); ?> <?php // include the footer // include("inc/inc-footer.php"); ?> login-check.php <?php ob_start(); session_start(); include("inc/inc-dbconnection.php"); include("inc/inc-online.php"); include("inc/inc-functions.php"); include("inc/inc-header.php"); include("inc/inc-navigation.php"); ?> <?php // standard header // print("<div class=\"subheader\"><div id=\"title\">Home > <span class=\"blue\">Login to your account</span></div>You can update your personal details and view orders in here. forgot your password? no worries recover it <a class=\"smart_links\" href=\"recover-password.php\">here</a>.</div>"); // check to see if the session exists // if(isset($_SESSION['id'])) { print("<div id=\"shopping_login_error\">You are already logged in.</div>"); include("inc/inc-footer.php"); exit; } // vars // $email = mysql_real_escape_string(trim($_POST['email'])); $password = mysql_real_escape_string(trim($_POST['password'])); $cookie = $_POST['remember']; // check for empty fields use javascript to // if(empty($email) || empty($password)) { standard_message("Error","You never filled in both login fields."); } // validate email // if(!(ereg ("^.+@.+\..+$", $email))) { standard_message("Error","Your e-mail address looks invalid."); } // see if the details are in the database // $querylogin = "SELECT `id`,`email`,`password`,`first_name` FROM `fcp_customers` WHERE `email`='$email' AND `password`='$password' LIMIT 1"; $resultslogin = mysql_query($querylogin) or die (mysql_error()); $row = mysql_fetch_array($resultslogin); // results from the login attempt // $num = mysql_num_rows($resultslogin); if($num != 1) { standard_message("Error","The details you have submitted don't appear to be in our database."); } // there was results so update the login timer and set a session // $querytimer = mysql_query("UPDATE `fcp_customers` SET `last_logged_in`=now() WHERE `email`='$email' AND `password`='$password'"); $_SESSION['id'] = $row['id']; $_SESSION['first_name'] = $row['first_name']; $_SESSION['logged_in'] = 'yes'; $cookie_id = $row['id']; $cookie_customer_name = $row['username']; // check if the remember is set value of remember is yes // if(isset($cookie)) { // if it is set the set a cookie // setcookie("customers_cookie_id", $cookie_id, time()+3600); setcookie("customers_cookie_customer", $cookie_customer_name, time()+3600); } // redirect to members page // header("Location: account.php"); ob_clean(); exit; ?> <?php // include the footer // include("inc/inc-footer.php"); ?> i can't seem to figure out why! thanks for any help guys Graham Link to comment https://forums.phpfreaks.com/topic/126355-rememer-me-cookie/ Share on other sites More sharing options...
revraz Posted September 29, 2008 Share Posted September 29, 2008 Where do you check to see if the cookie is set? Link to comment https://forums.phpfreaks.com/topic/126355-rememer-me-cookie/#findComment-653488 Share on other sites More sharing options...
mat-tastic Posted September 30, 2008 Share Posted September 30, 2008 You are only checking if the session has been set. The session gets destroyed after you close your browser. You need to check for the cookies. You have only set them. Link to comment https://forums.phpfreaks.com/topic/126355-rememer-me-cookie/#findComment-653523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.