Jump to content

login script, setting session variables, a small problem


jainsy

Recommended Posts

Hi guys,

 

Admittedly I didn't really write all of this, I'm just modifying some script Dreamweaver includes for users to register and login etc.

 

Anyway, what I'm trying to do below is to obtain the users id as stored as userID in the MySQL table and set it as a session variable $_SESSION['MM_UserID']  so I can use it later to insert records into a products table and link this back to the relevant user.

However, after the user has logged in and I use <?php echo ($_SESSION['MM_UserID']); ?> I get nothing appear at all..

 

Code is as follows;

<?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['loginEmail'])) {
  $loginUsername=$_POST['loginEmail'];
  $password=$_POST['loginPassword'];
  $MM_fldUserAuthorization = "userID";
  $MM_redirectLoginSuccess = "account.php";
  $MM_redirectLoginFailed = "sorry.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conn, $conn);
  	
  $LoginRS__query=sprintf("SELECT userEmail, userPassword, userID FROM users WHERE userEmail=%s AND userPassword=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"), GetSQLValueString($userID, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'userID');
    
    //declare three session variables and assign them
$_SESSION['MM_UserID'] = $loginUserID;
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    echo "<font color=#ff0000>Either your username or password were incorrect, please check and try again!</font><br><br>";
  }
}
?>

 

First time posting, liking the community.

 

Thanks in advance!!

 

yeah i have session_start() at the top of the page.

However, If i have <?php echo ($_SESSION['MM_Username']); ?> then the username appears fine but with <?php echo ($_SESSION['MM_UserID']); ?> nothing appears. Which why I was guessing the script above was not passing the UserID into the session but I couldnt work out why, this is really bugging me!!! ??

 

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.