Login In and Retriving info.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Login In and Retriving info.

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

session_start() needs to be on ALL pages you want to access session variables.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

[OT]Dreamweaver writes icky code...[/OT]

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

sessions

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

patrikG wrote:WOOT! Twig that's an unfair double-post!
But quick reply is sooo much easier than edit...

Mac
Post Reply