Jump to content

Help with session needed


lingo5

Recommended Posts

Hi,

I have created a login script that creates a user id session from the user email, like so:

// *** 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['distributor_email'])) {
  $loginUsername=$_POST['distributor_email'];
  $password=$_POST['distributor_password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "DIST_main.php";
  $MM_redirectLoginFailed = "index.php?failed=true";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_MySQLconnect, $MySQLconnect);
  
  $LoginRS__query=sprintf("SELECT distributor_email, distributor_password FROM t_distributors WHERE distributor_email=%s AND distributor_password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $MySQLconnect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );

$datetime = date("Y-m-d H:i:s",time());
    $query = "UPDATE mydatabase.t_distributors SET distributor_lastlogin= '$datetime' WHERE distributor_email='$loginUsername'";
     $result = mysql_query($query) or die(mysql_error()); 

  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

This works fine, but I need to create one more session to store the Company name of the logged in user.

I am struggling to do this as I am new to sessions.

Any help much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/253851-help-with-session-needed/
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.