...

View Full Version : $_SESSION returning different results on windows and linux



hinch
12-11-2008, 04:27 PM
I've encountered a little problem and I'm not sure why basically.

The site I'm working on has 3 login area's .

In the case of each login area I store a userID and various other information in a session.

On Member Login I store this:


$_SESSION['userid'] = $userdetails[0].",".$_POST['myusername'];

On Company Login I store this:


$_SESSION['corpid'] = $actual_id[0];

And on Admin Login I store this


$_SESSION['adminid'] = $userdetails[0].",".$userdetails[3].",".$userdetails[4];

Now here's where the fun begins.

On the userid the front end works perfectly on both the linux server and the windows dev machine when i do $_SESSION['userid'][0] or $_SESSION['userid'][1]

The corpid session always works fine since its only a single int stored.

The admin session is where the fun begins.
On windows doing a print_r of the session returns this

1,Administrator,emailaddress

perfect just what I want. on the linux server a print_r returns this though
Array ( [0] => Array )

So me thinking that perhaps I just need to explode out the string stored.


$adminid=explode(",",$_SESSION['adminid']);

Now print_r ($adminid); on windows returns this
Array ( [0] => 1 [1] => Administrator [2] => emailaddress )
again perfect just what I want but on linux it returns this
Array ( [0] => Array )

Am I being massively stupid with array handling here or am I missing something completely?

I'm a little confused since it works on the user front end fine and only appears to cause a problem in the admin area with the adminid session.

mic2100
12-11-2008, 05:02 PM
i have tested this one both a window and 2 different linux servers and i get the same response on all of them...

Array ( [0] => 1 [1] => admin [2] => email )

the code i used was just copied from ur examples


$_SESSION['adminid'] = "1,admin,email";

$adminid=explode(",",$_SESSION['adminid']);

print_r($adminid);

Fumigator
12-11-2008, 05:06 PM
Looks like the real problem is your $_SESSION['adminid'] is getting unset somewhere, for reasons unknown to me.

hinch
12-11-2008, 06:39 PM
i have tested this one both a window and 2 different linux servers and i get the same response on all of them...

Array ( [0] => 1 [1] => admin [2] => email )

the code i used was just copied from ur examples


$_SESSION['adminid'] = "1,admin,email";

$adminid=explode(",",$_SESSION['adminid']);

print_r($adminid);


I know confused the hell out of me too. especially since it works in all other area's just the admin area it fails in :(


Looks like the real problem is your $_SESSION['adminid'] is getting unset somewhere, for reasons unknown to me.

This could be a possiblity too but I can't for the life of me work out where/if and surely if it was being unset doing print_r on it wouldn't even return the word "array" if it was unset would it ?

Fumigator
12-11-2008, 08:36 PM
Well, yeah, not unset-- just an empty array is being assigned to it. Throw a bunch of print_r's in everywhere to see what happens to it...? I mean does it ever have the right value? This is what I like to call brute force troubleshooting, just spam enough output until the culprit is revealed. :p

hinch
12-11-2008, 09:09 PM
done that on the windows dev server and its fine the session adminid contains the correct information all the way through until the end of the footer

on the linux server though if i print_r it even just after its been set it contains just "Array"

I still don't understand why the userid session which is created in exactly the same way works fine on both the windows and the linux server.

Fumigator
12-11-2008, 09:57 PM
So it's not really $_SESSION['adminid'], it's $userdetails[0].",".$userdetails[3].",".$userdetails[4];

Where's that stuff coming from? Does it look OK from inception?

hinch
12-11-2008, 10:18 PM
yeah its all pulling the correct details out and its populating it correctly. if I echo out the string before setting it into the session its correct.

Just as soon as I dump it into a session it fails but again its only on the linux server its failing on the windows server its working perfectly.

hinch
12-13-2008, 01:41 PM
any one else got any suggestions of things I can try?

abduraooft
12-13-2008, 01:54 PM
I know confused the hell out of me too. especially since it works in all other area's just the admin area it fails in Have you made any error in choosing the right operator(say a = instead of ==) somewhere in the program? Could you post the complete code in that file?

hinch
12-13-2008, 04:39 PM
Have you made any error in choosing the right operator(say a = instead of ==) somewhere in the program? Could you post the complete code in that file?

can't really post the entire code no since its in excess of 5k lines

Basicaly though I create the session as above thats a copy and paste code.

Then when I want to retrieve anything out of it usually I just do

<?php echo $_SESSION['adminid'][0];?>
<?php echo $_SESSION['adminid'][1];?>
<?php echo $_SESSION['adminid'][2];?>

etc when I noticed that didn't work on the linux machine thats when I then tried splitting it down into an array $adminid via explode again exact code pasted above.

As far as i'm aware though there's no operand difference between = and == in linux and windows versions of php so if it works on windows it should work on linux all I can think is that there's a session handling issue.

The main site is under domain/ the admin panel is under domain/admin/ though do sessions have session domains perhaps ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum