Patrick3002 Posted February 22, 2007 Share Posted February 22, 2007 My login script will not stay logged in... If i refresh the page its fine but if i go to another page then back to a page im logged out. Or i i click the index.php main logo twice at the first time after i click it it display a blank area where its supposed to say im logged in and then the second time i click it it brings the login form back up to login again... Heres my login script: $email=$_POST['email']; $password=$_POST['password']; $remember=$_POST['remember']; $_SESSION['email'] = $email; $_SESSION['password'] = $password; $_SESSION['remember'] = $remember; if ( !$email || !$password ) { echo " "; $email = false; $password = false; session_destroy(); } else { include_once("includes/config.php"); $table = "lyrics_usr"; if ( isset($remember) ) { setcookie("cookname", $_SESSION['email'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/"); $logged = "Welcome <b>$_SESSION[email]</b>, you are logged in."; } else { $logged = "You are not logged in."; } if ( !$email || !$password ) { echo "Please enter your e-mail address and/or password! <a href='javascript:history.go(-1)'>back</a>"; $_SESSION["email"] = false; $_SESSION["password"] = false; session_destroy(); } else { $sql = "SELECT `email`, `password` FROM `$table` WHERE `email` = '$email' AND `password` = '$password'"; $q = mysql_query($sql); if( mysql_num_rows($q) > 0 ) { $logged = "Welcome <b>$_SESSION[email]</b>, you are logged in."; } else { echo "Your login was NOT successful, please make sure you have entered the correct information. <a href='javascript:history.go(-1)'>back</a>"; $_SESSION["email"] = false; $_SESSION["password"] = false; session_destroy(); } } } Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/ Share on other sites More sharing options...
redarrow Posted February 22, 2007 Share Posted February 22, 2007 can u post all the code please cheers Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/#findComment-191342 Share on other sites More sharing options...
Patrick3002 Posted February 22, 2007 Author Share Posted February 22, 2007 Sorry, here it is: <?php /******************************************************** ****-------------------------------------------------**** ****---- Login Script Starts Here -------------------**** ****-------------------------------------------------**** ********************************************************/ $email=$_POST['email']; $password=$_POST['password']; $remember=$_POST['remember']; $_SESSION['email'] = $email; $_SESSION['password'] = $password; $_SESSION['remember'] = $remember; if ( !$email || !$password ) { echo " "; $email = false; $password = false; session_destroy(); } else { include_once("includes/config.php"); $table = "lyrics_usr"; if ( isset($remember) ) { setcookie("cookname", $_SESSION['email'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/"); $logged = "Welcome <b>$_SESSION[email]</b>, you are logged in."; } else { $logged = "You are not logged in."; } if ( !$email || !$password ) { echo "Please enter your e-mail address and/or password! <a href='javascript:history.go(-1)'>back</a>"; $_SESSION["email"] = false; $_SESSION["password"] = false; session_destroy(); } else { $sql = "SELECT `email`, `password` FROM `$table` WHERE `email` = '$email' AND `password` = '$password'"; $q = mysql_query($sql); if( mysql_num_rows($q) > 0 ) { $logged = "Welcome <b>$_SESSION[email]</b>, you are logged in."; } else { echo "Your login was NOT successful, please make sure you have entered the correct information. <a href='javascript:history.go(-1)'>back</a>"; $_SESSION["email"] = false; $_SESSION["password"] = false; session_destroy(); } } } if ( !isset($SESSION['email']) ) { $tbtext = "Sign-in"; } else { $tbtext = "Welcome!"; } if ( !isset($_SESSION['email']) ) { echo "<form name=\"login\" method=\"post\" action=\"index.php\"> <table class=\"signup tablebrdr\" width=\"324\" height=\"171\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td height=\"20\" colspan=\"2\" bgcolor=\"#00CCFF\"><strong>$tbtext</strong></td> </tr> <tr > <td width=\"78\" height=\"31\" align=\"right\" valign=\"bottom\" bgcolor=\"#FFFFFF\">E-mail: </td> <td width=\"246\" align=\"left\" valign=\"bottom\" bgcolor=\"#FFFFFF\"> <label> <input class=\"input2\" name=\"email\" type=\"text\" size=\"30\" /> </label> </td> </tr> <tr> <td height=\"31\" align=\"right\" bgcolor=\"#FFFFFF\">Password:</td> <td bgcolor=\"#FFFFFF\"> <label> <input class=\"input2\" name=\"password\" type=\"text\" size=\"30\" /> </label> </td> </tr> <tr> <td height=\"44\" align=\"right\" valign=\"middle\" bgcolor=\"#FFFFFF\"> </td> <td align=\"left\" valign=\"top\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"remember\" value=\"checkbox\" /> Remember Me </td> </tr> <tr> <td height=\"24\" align=\"center\" bgcolor=\"#FFFFFF\"> <input class=\"signupbt\" type=\"image\" src=\"images/login.jpg\" name=\"login\" value=\"submit\" /> </td> </form> <form name=\"signup\" action=\"join.php\" method=\"post\"> <td align=\"left\" bgcolor=\"#FFFFFF\"> <input class=\"signupbt\" src=\"images/signup.jpg\" type=\"image\" name=\"signup\" value=\"submit\" /> </td> </form> </tr> <tr> <td height=\"19\" bgcolor=\"#FFFFFF\"> </td> <td align=\"right\" bgcolor=\"#FFFFFF\"><a href=\"forgot_login.php\">Forgot your password?</a> </td> </tr> </table>"; } else { echo "$logged"; } ?> Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/#findComment-191344 Share on other sites More sharing options...
Patrick3002 Posted February 22, 2007 Author Share Posted February 22, 2007 I can never get help here anymore, what happened? Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/#findComment-191360 Share on other sites More sharing options...
Patrick3002 Posted February 22, 2007 Author Share Posted February 22, 2007 I can't figure it out, my login script will not stay logged in, i have start_session() on all of my pages.... Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/#findComment-191370 Share on other sites More sharing options...
Patrick3002 Posted February 22, 2007 Author Share Posted February 22, 2007 Anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/#findComment-191378 Share on other sites More sharing options...
Patrick3002 Posted February 22, 2007 Author Share Posted February 22, 2007 Is there some kind of setting in php.ini? Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/#findComment-191385 Share on other sites More sharing options...
Patrick3002 Posted February 22, 2007 Author Share Posted February 22, 2007 For some reason i cant have the login script on the same page with the form on it...? I made a separate page for the login code and it works now, anyone know why i cant have it on the same page? Thanks! Link to comment https://forums.phpfreaks.com/topic/39640-my-login-script/#findComment-191415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.