Session Variable blank - what am I doing wrong?

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
BravehearT1326
Forum Newbie
Posts: 1
Joined: Mon Sep 25, 2006 6:53 am

Session Variable blank - what am I doing wrong?

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post by phpdevuk »

ah scratch that next time I'll read the code, lol
Post Reply