Jump to content

remember function login page


gwolff2005

Recommended Posts

Hi guys I need your help! I wrote a login script with a remember button, but the remember function does not work. What is wrong:

 

<?php require_once('Connections/Login.php'); ?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "intro.php";
$MM_redirectLoginFailed = "login.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Login, $Login);

$LoginRS__query=sprintf("SELECT name, results, username, password FROM users WHERE username='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 



$LoginRS = mysql_query($LoginRS__query, $Login) or die(mysql_error());
$row = mysql_fetch_array($LoginRS);          // ADDED
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
   $loginStrGroup = "";
   //declare two session variables and assign them
   $_SESSION['MM_Username'] = $loginUsername;
   $_SESSION['MM_password'] = $row['password'];
   $_SESSION['MM_UserGroup'] = $loginStrGroup;   
   $_SESSION['MM_name'] = $row['name'];   // CHANGED 
   $_SESSION['MM_results'] = $row['results'];


if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
if(isset($_POST['remember'])){
      setcookie("cookname", $_SESSION['MM_username'], time()+60*60*24*100, "/");
      setcookie("cookpass", $_SESSION['MM_password'], time()+60*60*24*100, "/");
   }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #000033;
}
#Layer1 {
position:absolute;
left:111px;
top:69px;
width:473px;
height:119px;
z-index:1;
}
#Layer2 {
position:absolute;
left:113px;
top:176px;
width:354px;
height:17px;
z-index:2;
}
.style5 {
font-size: 11px;
color: #000033;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-style: italic;
}
-->
</style>
</head>
<body>
<div id="Layer1">
  <form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" id="form1">
    <table width="400" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td width="100" class="style3">Username:</td>
        <td><div align="left">
            <input name="username" type="text" class="style3" id="username" />
        </div></td>
      </tr>
      <tr>
        <td width="100"><span class="style3">Password:</span></td>
        <td><div align="left">
            <input name="password" type="password" class="style3" id="password" />
        </div></td>
      </tr>
      <tr>
        <td class="style3">Remember me: </td>
        <td><input name="remember" type="checkbox" id="remember" value="checkbox" /></td>
      </tr>
      <tr>
        <td width="100"> </td>
        <td><div align="left">
            <input name="Submit" type="submit" class="style3" value="Submit" />
        </div></td>
      </tr>
    </table>
  </form>
</div>
<div class="style5" id="Layer2">If you don't have a login, please register <a href="register.php" target="_self">here</a>. </div>
<div align="center"></div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/153601-remember-function-login-page/
Share on other sites

To set the cookie, something like:

<?php

setcookie("username", $userNameVar, time()+3600);
setcookie("userpass", $userPassVar, time()+3600);

?>

And:

<?php

if(isset($_COOKIE['username']) && isset($_COOKIER['userpass'])){
   include("yourMainPage.php");
}
else {
   include("yourLoginPage.php");
}

?>

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.