Jump to content

My login script...


Patrick3002

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.