Jump to content

Recommended Posts

I have the following login page that logs users into another restricted page.

 

But when i get to the next page how can I get the ID and details from the db of that member, can someone guide me in the right direction?

 

Log in Page:

<?php
// *** Validate request to login to this site.
session_start();

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

if (isset($_POST['userN'])) {
  $loginUsername=$_POST['userN'];
  $password=$_POST['passsW'];
  $MM_fldUserAuthorization = "auth";
  $MM_redirectLoginSuccess = "Private.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_reConn, $reConn);
  	
  $LoginRS__query=sprintf("SELECT ref_name, ref_pass, ref_auth FROM ref_members WHERE ref_name='%s' AND ref_pass='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
   
  $LoginRS = mysql_query($LoginRS__query, $reConn) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'ref_auth');
    
    //declare two session variables and assign them
    $GLOBALS['MM_Username'] = $loginUsername;
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;	      

    //register the session variables
    session_register("MM_Username");
    session_register("MM_UserGroup");

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

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/83978-list-correct-details-after-login/
Share on other sites

It looks like you are registering their username on this line

session_register("MM_Username");

 

Just as a note, unless your using an old version of PHP, you should be registering your sessions like this

$_SESSION['MM_Username'] = "Their Username";

 

I'm assuming that their username is unique. So to get their information on another page, you would just do a query like this.

 

<?php
session_start();

$query = mysql_query("SELECT username, col, col3 FROM users WHERE username='{$_SESSION['username']}'")or die(mysql_error());

?>

pocobueno1388 you mentioned using the following:

 

 $_SESSION['MM_Username'] = "Their Username";

 

In my log in code then would I replace what I have :

 

 

    //declare two session variables and assign them
   $GLOBALS['MM_Username'] = $loginUsername;
   $GLOBALS['MM_UserGroup'] = $loginStrGroup;	      

   //register the session variables
   session_register("MM_Username");
   session_register("MM_UserGroup");

 

with

    //declare two session variables and assign them
   $GLOBALS['MM_Username'] = $loginUsername;
   $GLOBALS['MM_UserGroup'] = $loginStrGroup;	      

   //register the session variables
   $_SESSION['MM_Username'] = "MM_Username";
   $_SESSION['MM_UserGroup'] = "MM_UserGroup";

 

or simply do away with the globals and have the following:

 

   //register the session variables
   $_SESSION['MM_Username'] = $loginUsername;
   $_SESSION['MM_UserGroup'] = $loginStrGroup;

 

Thanks

 

thanks revraz, posted as I was reply to mine as well.

 

I went in and reduced the code and used

 

 $_SESSION['MM_Username'] = $loginUsername;

 

and then used a simple echo to display the session on the other page and it displayed so answered that my self

the best way try it...

 

thanks so far

That's what I say, what's the worse that can happen right?  ;D

 

the best way try it...

 

 

 

oh! you would not imagine, yup you probably would. but I find it the best way and thats how I learnt PHP etc thanks again peps :-)

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.