Page 1 of 1

Session Variable blank - what am I doing wrong?

Posted: Mon Sep 25, 2006 5:07 pm
by BravehearT1326
Hi there

Have the following PHP code for a login screen.

Code: Select all

<?php require_once('Connections/Like_A_Like.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['Username'])) {
$loginUsername=$_POST['Username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "test page address here";
$MM_redirectLoginFailed = "failed page address goes here";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Like_A_Like, $Like_A_Like);

$LoginRS__query=sprintf("SELECT username, password FROM registered_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, $Like_A_Like) 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 );
}
}
?>

Problem is when I attempt to display the username entered on the successful login page it doesn't show anything. I've tried different methods but to no avail.

What am I doing wrong???? I'm new to this and it's really starting to bug me..

any help / guidance appreciated.

Posted: Mon Sep 25, 2006 5:17 pm
by Luke
haven't looked over it too much, but session_register is deprecated... read all the cautions etc. on that page
Use $_SESSION instead

Posted: Mon Sep 25, 2006 5:58 pm
by phpdevuk
ah scratch that next time I'll read the code, lol