Jump to content

Recommended Posts

Hi guys,

my remember me function does not work. It would be great if anyone could tell me whats wrong or missing in the code. Thanks so much in advance....

 

<?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 id, resultspo, resultsmo, resultspassion, firstname, 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_resultspo'] = $row['resultspo'];
   $_SESSION['MM_resultsmo'] = $row['resultsmo'];
   $_SESSION['MM_resultspassion'] = $row['resultspassion'];
   $_SESSION['id'] = $row['id'];
   $_SESSION['newpo'] = $row['resultspo'];
   $_SESSION['newmo'] = $row['resultsmo'];
   $_SESSION['MM_firstname'] = $row['firstname'];


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:71px;
top:83px;
width:473px;
height:119px;
z-index:1;
}
#Layer2 {
position:absolute;
left:71px;
top:212px;
width:354px;
height:17px;
z-index:2;
}
.style5 {
font-size: 11px;
color: #000033;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-style: italic;
}
#Layer3 {
position:absolute;
left:110px;
top:23px;
width:245px;
height:19px;
z-index:3;
}
#Layer4 {
position:absolute;
left:71px;
top:17px;
width:235px;
height:19px;
z-index:3;
}
#Layer5 {
position:absolute;
left:360px;
top:14px;
width:401px;
height:333px;
z-index:4;
}
-->
</style>
</head>
<body>
<div id="Layer1">
  <form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" target="_top" 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 id="Layer4"><a href="pics/buttonlogin.php"><img src="pics/buttonlogin.jpg" alt="" name="" width="257" height="19" border="0" /></a></div>
<div id="Layer5">
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="400" height="325">
    <param name="flash_component" value="ImageViewer.swc" />
    <param name="movie" value="login.swf" />
    <param name="quality" value="high" />
    <param name="FlashVars" value="flashlet={imageLinkTarget:'_blank',captionFont:'Verdana',titleFont:'Verdana',showControls:true,frameShow:false,slideDelay:5,captionSize:10,captionColor:#333333,titleSize:10,transitionsType:'Random',titleColor:#333333,slideAutoPlay:false,imageURLs:['img1.jpg','img2.jpg','img3.jpg'],slideLoop:false,frameThickness:2,imageLinks:['http://macromedia.com/','http://macromedia.com/','http://macromedia.com/'],frameColor:#333333,bgColor:#FFFFFF,imageCaptions:[]}" />
    <embed src="login.swf" quality="high" flashvars="flashlet={imageLinkTarget:'_blank',captionFont:'Verdana',titleFont:'Verdana',showControls:true,frameShow:false,slideDelay:5,captionSize:10,captionColor:#333333,titleSize:10,transitionsType:'Random',titleColor:#333333,slideAutoPlay:false,imageURLs:['img1.jpg','img2.jpg','img3.jpg'],slideLoop:false,frameThickness:2,imageLinks:['http://macromedia.com/','http://macromedia.com/','http://macromedia.com/'],frameColor:#333333,bgColor:#FFFFFF,imageCaptions:[]}" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="325"> </embed>
  </object>
</div>
<div align="center"></div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/156090-remember-me-function-does-not-work/
Share on other sites

that's because PHP is case sensitive when it comes to variable names .. spot the difference?

 

$_SESSION['MM_Username'] = $loginUsername;

 

versus

 

setcookie("cookname", $_SESSION['MM_username'], time()+60*60*24*100, "/");

 

*HINT: the 'u' in username is uppercase when you declare the session var, but lowercase when you try and use it in a cookie.

 

could be why your not being remembered since the username you're expecting isn't being stored in the cookie.

 

did you read the cookie when troubleshooting?  you would've seen that right off the bat.

how - or where - are you checking the stored cookie information against the database / user?

 

i mean, you can set cookies all you want, but if that's all you do, you can't expect much to happen thereafter.

 

are your passwords encrypted in the database?  make sure the login credential's are correct.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.