Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session variable error - what am I missing here?

Status
Not open for further replies.

Microbe

Programmer
Oct 16, 2000
607
AU
Hey all,

I have a lot of experience with ASP but am fairly new to (and am enjoying) PHP.

Can someone point out what the problem here is? I can't figure it for the life of me. This code is from a login page.

Code:
    //declare two session variables and assign them
    $GLOBALS['Username'] = $loginUsername;
    $GLOBALS['UserGroup'] = $loginStrGroup;	      

    //register the session variables
    session_register("Username");
    session_register("UserGroup");

	echo("global = ". $GLOBALS['UserGroup']. "  :: group = " . $_SESSION['UserGroup'] . " ::  name = " . $_SESSION['Username'] . " :: db = " . $row_users['userAdministratorLevel']." :: loginstrgroup =  " . $loginStrGroup);
	exit();
which produces the result
Code:
global = 40 :: group = 0 :: name = steve :: db = 40 :: loginstrgroup = 40
Can anyone explain why the uUsername session is fine, but the UserGroup session is "0" where all the variables associated with it are correct (40).

What am I missing here?

Steve Davis
ttf(a)HaHaHa.com.au

Me? I can't even spell ASP!

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination.
 
if you have register_globals off (what is recommended) use:

Code:
//register the session variables
$_SESSION['Username'] = $loginUsername;
$_SESSION['UserGroup'] = $loginStrGroup;



gry online
 
Thanks for that, in fact, that is how I have made it work.

I assume that "register_globals" is a server variable in the ini file.

The code was created by Dreamweaver MX 2004...I should know better...especially after it trashed a complete website yesterday...a week's work down the drain :p

Steve Davis
ttf(a)HaHaHa.com.au

Me? I can't even spell ASP!

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination.
 
You also need to have the statement
Code:
session_start()
before your script outputs any data. Put this statement in any script where you want to access the session variables.

Ken
 
Thanks Ken. I have that...or (as I understand it) the session variales wouldn't work at all.

Steve Davis
ttf(a)HaHaHa.com.au

Me? I can't even spell ASP!

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top