session stupidity

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
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

session stupidity

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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!
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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!
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tested on 4.4.1? Just in case it's a bug you need to report...

Mac
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 )
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply