Sessions and register globals

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
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Sessions and register globals

Post by Jade »

[Admin Edit: moved from the sessions sticky thread]

Quick Question.

I know sessions work different with register_globals on and off. I'm not quite sure i understand how they work differently. I run an internet game of my own server and i leave register_globals off. However, I also develop internet games for other people where they can just install them on their servers. I'm hhaving trouble writing a login script using sessions where it doesn't matter if register globals is on or off. Any suggestions?
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

It shouldn't matter if you explicit use $_SESSION for all session data, as Jason posted above..

Edit/Add: If you NEVER user $blah and ALWAYS use $_SESSION['blah'] when setting and reading session data, there is no way register_globals makes a difference, if so it would be a bug in PHP i believe...
Last edited by Stoker on Sun Mar 02, 2003 5:05 pm, edited 1 time in total.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

Actually, I think there is a difference.

In my game, if i turn register_globals on and you log in as PHP you are taken to the account that is actually for the member ASP...etc. Its like the sessions aren't corresponding to the right member, even though i start a new one for EVERY member. There has to be a difference if this is only happening to me with register_globals on.

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

Post by twigletmac »

Unless you are switching PHP versions then there is no reason why sessions would not work as expected with reg_globals on or off - $_SESSION exists either way so something else might be affecting the code.

Mac
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

Well, then I have no clue why my sessions won't work with register globals on. I have over 1k members on my site and when i tried installing a chat that required register_globals to be on my members were logging in and then their sessions were screwing up. If you have any clues why, let me know. It would help lots.

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

Post by twigletmac »

If you are using $_SESSION and add some code that uses session_register() then sessions will be messed up, the superglobals and the old session functions do not play nicely together.

Maybe that could be part of your problem although without seeing the code it's difficult to diagnose.

Mac
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

My sessions:

session_start();

define("SESSION_LENGTH", 60);

$_SESSION["name"] = $_POST['loginname'];
$_SESSION["password"] = $_POST['password'];

$membername = $_SESSION["name"];
$memberpass = $_SESSION["password"];


that's how i'm doing it.

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

Post by twigletmac »

There's nothing in the chat script that uses sessions?

Mac
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

nope, nothing. Weird huh? Maybe it does have to do with the sessions....dunno

Jade
Post Reply