Page 1 of 1

session stupidity

Posted: Tue Nov 15, 2005 5:22 pm
by shiznatix
ok im no novice but this is rediculous

Code: Select all

$_SESSION['query'] = $query;

print_r($_SESSION);
//prints the correct everything

$query = mysql_query($query);
print_r($_SESSION);
//ALL OF A SUDDEN SESSION HAS CHANGED! WTF!
anyone know why that happens?

edit: PHP version 4.4.0

Posted: Tue Nov 15, 2005 5:42 pm
by shiznatix
after some testing by timvw it seams that this only happens in php 4.4.0 so beware! this caused me almost a hour of greif!

Posted: Tue Nov 15, 2005 5:52 pm
by AKA Panama Jack
Sounds like you have something in the PHP config that might need changing. Don't ask me what as I can't think of it of the top of my head.

My developement server is PHP 4.4.0 and I am always using alot of stored session data between pages and I have never run into this kind of problem.

Posted: Tue Nov 15, 2005 6:18 pm
by shiznatix
well i don't know but both me and timvw had the same problem so i am thinking it has to do with the default config. my workaround was:

Code: Select all

$_SESSION['queryb'] = $queryb

$query = mysql_query($queryb) or die(mysql_error());
//now i just use $query and all is well and happy.
what seams to happen is $_SESSION will follow the variable you set it to around the entire page starting from where you first set it so it will reset itself after you change the original value of the variable you set session to. it also seamed to have a effect if i named the session key to the same name as the variable that was changing but i can not put money on that, i just believe i tried that and it did not work. really strange, bewwwwwaaaarrrreeee! php 4.4.0 has this ability to ruin your night!

Posted: Tue Nov 15, 2005 6:31 pm
by AKA Panama Jack
Oh, I didn't notice that you were using the same variable name...

Code: Select all

$_SESSION['query'] = $query;

$query = mysql_query($query);
Do you have Register Globals On in your php.ini? If Register Globals is enabled then any changes in the $query variable will also be reflected in the $_SESSIONS['query'] variable. So the result of the mysql_query will be in both the $query and $_SESSION['query'] variables. To stop this from happening you need to do what you indicated in your last post or disable Register Globals in the php.ini.

Posted: Tue Nov 15, 2005 7:07 pm
by shiznatix
no register globals is not on. i know a bit better than that :wink: . it just happens with 4.4.0 though, timwv tested with 4.3.# and 5.0 and 4.4.0 and he was only able to duplicate the error with 4.4.0. i don't know whats up with this

Posted: Wed Nov 16, 2005 7:47 am
by twigletmac
Have you tested on 4.4.1? Just in case it's a bug you need to report...

Mac

Posted: Wed Nov 16, 2005 8:22 am
by shiznatix
no but if anyone has 4.4.1 then please test that for me so we can see what version this bug is for

Posted: Wed Nov 16, 2005 9:37 am
by timvw

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

session_start();

$query = "shiz is mad";
$_SESSION['query'] = $query;
print_r($_SESSION);
$query = "timvw is not that mad";
print_r($_SESSION);

?>
Output for PHP 4.3.10-16
Array ( [query] => shiz is mad )
Array( [query] => shiz is mad )
Output for PHP 5.0.5
Array( [query] => shiz is mad )
Array( [query] => shiz is mad )
Output for PHP 4.4.0
Array ( [query] => shiz is mad )
Array ( [query] => timvw is not that mad )

Posted: Wed Nov 16, 2005 9:51 am
by JAM
Apache/1.3.34 (Unix) mod_jk/1.1.0 mod_throttle/3.2.0 Embperl/2.0b8 mod_perl/1.29 PHP/4.4.1 mod_ssl/2.8.25 OpenSSL/0.9.8a

Code: Select all

Array
(
    [query] => shiz is mad
)
Array
(
    [query] => shiz is mad
)
Thats using 4.4.1 so the bug is earlier.

Posted: Wed Nov 16, 2005 10:21 am
by AKA Panama Jack
I'll be damned you are right. :) Guess I have never had any variables that were the same as session array elements. :)

Looks like they fixed it in 4.4.1.

Posted: Wed Nov 16, 2005 11:02 am
by s.dot
PHP 4.3.11

Code: Select all

Array ( [query] => shiz is mad )
Array ( [query] => shiz is mad )
So it looks like it works properly in PHP 4.3.11, then fails to work properly in 4.4.0, then works properly in 4.4.1.