Page 1 of 1

Login In and Retriving info.

Posted: Tue Oct 05, 2004 12:25 pm
by moiseszaragoza
LOGIN.PHP
This is the Log in Script I'm Using

Code: Select all

<?php require_once('../Connections/Uswr.php'); ?>
<?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['txtFirstName'])) {
  $loginUsername=$_POST['txtFirstName'];
  $password=$_POST['Password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "P3.php";
  $MM_redirectLoginFailed = "http://Cnn.com";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_iaOnline, $iaOnline);
  
  $LoginRS__query=sprintf("SELECT 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, $iaOnline) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //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 );
  }
}

?>
This Works But It dose not send a session across to another page

Posted: Tue Oct 05, 2004 12:41 pm
by feyd
session_start() needs to be on ALL pages you want to access session variables.

Posted: Wed Oct 06, 2004 3:48 am
by twigletmac
[OT]Dreamweaver writes icky code...[/OT]

Mac

Posted: Wed Oct 06, 2004 3:49 am
by twigletmac
BTW, session_register() does not play nicely with $_SESSION and is a totally uneccessary function if you're using PHP 4.1 or greater.

Mac

sessions

Posted: Wed Oct 06, 2004 4:03 am
by phpScott
you might want to have a little look at the [php_man]session[/php_man] to use the correct type of session handling between your pages.

phpScott

Posted: Wed Oct 06, 2004 4:19 am
by patrikG
WOOT! Twig that's an unfair double-post! Looks like a sever, err, severe, infringement on the rules laid down by CAP++ (see: viewtopic.php?p=136808#136808).
Well, we'll settle for a cup of tea with milk, I reckon. Someone put the kettle on, please.

Posted: Wed Oct 06, 2004 5:01 am
by twigletmac
patrikG wrote:WOOT! Twig that's an unfair double-post!
But quick reply is sooo much easier than edit...

Mac