Jump to content


Photo

[SOLVED] Losing one session variable, rest are still intact


  • Please log in to reply
8 replies to this topic

#1 da_beaver

da_beaver
  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationEngland

Posted 14 March 2006 - 01:08 PM

Hi,

I am setting session variables on a page then doing a header/location redirect to a second page however I am losing one of my session variables. Not all of them, just one.

Here are some details/comments:

I am doing a session_start() on ALL of my pages, right at the top of each page

I have tried session_write_close() before doing the redirect

A print_r of $_SESSION on the first page shows all of the variables intact before the redirect is attempted

There is nothing in the code or in an included file that unsets/destroys/overwrites the session variable.

The code that sets the variable is not within an output buffer

PHP version 4.3.1, Apache version 2.0.5.2 running on Windows 2000

Surely this shouldn't happen? If I was losing the entire session that would kind of be understandable but losing ONE variable out of about 10 or 11 is very strange.

Has anyone experienced this before or can anyone offer an explanation? Let me know if you need any further details.

Thanks for any advice offered.

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 14 March 2006 - 01:35 PM

do you have register_globals turned on? i found that one of my scripts behaved this way when i installed it on a server with register_globals on. what happened was that i had a $_SESSION['user'] variable, and on one page, i also had a plain $user variable. well, needless to say, with register_globals on, it overwrote my session variable anyway.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 da_beaver

da_beaver
  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationEngland

Posted 14 March 2006 - 01:44 PM

[!--quoteo(post=354872:date=Mar 14 2006, 01:35 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 14 2006, 01:35 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
do you have register_globals turned on? i found that one of my scripts behaved this way when i installed it on a server with register_globals on. what happened was that i had a $_SESSION['user'] variable, and on one page, i also had a plain $user variable. well, needless to say, with register_globals on, it overwrote my session variable anyway.
[/quote]

I've just checked the .ini file and register_globals is set to off.

Thanks for the advice though, I hadn't thought of checking that.

#4 bluebyyou

bluebyyou
  • Members
  • PipPipPip
  • Advanced Member
  • 234 posts
  • LocationIllinois

Posted 25 June 2007 - 11:39 PM

I am having the same problem as da_beaver, Is it a problem with the settings in PHP or is there some other cause for this? My version is 4.3.11 and register globals is on.
As we enjoy great advantages from the inventions of others, we should be glad of an opportunity to serve others by an invention of ours." - Ben Franklin

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 June 2007 - 11:42 PM

and register globals is on


Can you switch them off? Otherwise, you'll need to rename your variables. There is a conflict as described by obsidian.

#6 bluebyyou

bluebyyou
  • Members
  • PipPipPip
  • Advanced Member
  • 234 posts
  • LocationIllinois

Posted 25 June 2007 - 11:46 PM

I just wasn't sure If that had solved his problem. So no I cant swith to off, I dont have access, but changing the variable name worked. Thank you. (So if a moderator can, I think this topic can be set to solved)
As we enjoy great advantages from the inventions of others, we should be glad of an opportunity to serve others by an invention of ours." - Ben Franklin

#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 June 2007 - 11:53 PM

You can set the topic to solved yourself. Its in the bottom left corner.

#8 bluebyyou

bluebyyou
  • Members
  • PipPipPip
  • Advanced Member
  • 234 posts
  • LocationIllinois

Posted 26 June 2007 - 01:57 AM

No I cant I didnt start it so its not there.
As we enjoy great advantages from the inventions of others, we should be glad of an opportunity to serve others by an invention of ours." - Ben Franklin

#9 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 June 2007 - 01:59 AM

Done.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users