Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Join the forums now, and start posting to receive access to our Scripts Vault!
Home
Forum
Help
Login
Register
BBGameZone.net
»
Webmasters
»
Coding Discussion
»
Code Help
»
Losing PHP $_SESSION data
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: Losing PHP $_SESSION data (Read 1006 times)
CygnusX
Level 24
Posts: 303
Reputation: +3/-2
Losing PHP $_SESSION data
«
on:
December 01, 2010, 10:49:39 AM »
I'm storing an array inside of a session variable, and for some reason, the data is being lost when I change from page to page. All other data remains, but the session data for my stored array seems to vanish. What makes this even more odd to me is that the session can hold the data on my home PC, but not my server....
Any ideas?
Logged
Lords of Midnight
Chris
Game Owner
Level 35
Posts: 2,217
Reputation: +28/-1
Re: Losing PHP $_SESSION data
«
Reply #1 on:
December 01, 2010, 11:04:45 AM »
session_start();
Make sure no links point to another subdomain like
www.something.com
and something.com use different sessions.
Logged
www.lordsgame.com
|
www.SamuraiMMORPG.com
|
www.Moonstone-RPG.com
|
www.GalacticImperator.com
|
Europe1300.eu
CygnusX
Level 24
Posts: 303
Reputation: +3/-2
Re: Losing PHP $_SESSION data
«
Reply #2 on:
December 01, 2010, 11:16:22 AM »
I wish it were that easy : P
I've got this at the top of the page:
session_start();
global $_SESSION;
global $_GET;
further down i have something similar to:
if(empty($_SESSION['NumTrades']))
{
$rand_keys = array_rand($Item, 5);
$_SESSION['TrueValue'] = 0;
$_SESSION['Offer'] = 0;
$_SESSION['NumTrades'] = 1;
$_SESSION['Gold'] = 0;
$MyItems = array();
$MyItems[0] = $rand_keys[0];
$MyItems[1] = $rand_keys[1];
$MyItems[2] = $rand_keys[2];
$MyItems[3] = $rand_keys[3];
$MyItems[4] = $rand_keys[4];
$_SESSION['Item'] = $MyItems;
}
Where $Item is a large array of items => values.
I then have links on the page that are self referencing (ie, index.php?id=4), and when I do this, the value in $_SESSION['NumTrades'] will echo just fine... but the value in $_SESSION['Item'] is getting lost.
«
Last Edit: December 01, 2010, 11:18:17 AM by CygnusX
»
Logged
Lords of Midnight
CygnusX
Level 24
Posts: 303
Reputation: +3/-2
Re: Losing PHP $_SESSION data
«
Reply #3 on:
December 01, 2010, 11:45:02 AM »
No real solution, but I found a work around.
PHP did not like me declaring $Item and $_SESSION['Item']. I changed $_SESSION['Item'] to $_SESSION['MyItem'], and it works. Very odd.
Logged
Lords of Midnight
Nox
Level 35
Posts: 767
Reputation: +12/-2
Re: Losing PHP $_SESSION data
«
Reply #4 on:
December 01, 2010, 12:37:59 PM »
The change of name ... I expect this is only a part of code... isn't it possible that it gets overwritten somewhere?
What if you'd have $MyItem and $_SESSION['Item'] ?
Logged
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366
(a must-watch) | Join
BOINC
- no longer a hype, but you can help never the less
CygnusX
Level 24
Posts: 303
Reputation: +3/-2
Re: Losing PHP $_SESSION data
«
Reply #5 on:
December 01, 2010, 01:07:37 PM »
It was very short code... only 400 lines with 50 of those lines dedicated to making the $Items array. It was not being overwritten as the code worked just fine on my local machine, but failed once I moved it to the server. All code was contained in 1 file (part of the micro economics competition that Chris posted). I changed all 4 instances of $_SESSION['Item'] to $_SESSION['MyItem'], and all problems were solved. PHP version 5.2.4.
Logged
Lords of Midnight
Winawer
Level 6
Posts: 27
Reputation: +0/-0
Re: Losing PHP $_SESSION data
«
Reply #6 on:
December 01, 2010, 01:18:48 PM »
Is register_globals on?
Logged
Nox
Level 35
Posts: 767
Reputation: +12/-2
Re: Losing PHP $_SESSION data
«
Reply #7 on:
December 01, 2010, 01:20:31 PM »
Might be headshot
Logged
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366
(a must-watch) | Join
BOINC
- no longer a hype, but you can help never the less
CygnusX
Level 24
Posts: 303
Reputation: +3/-2
Re: Losing PHP $_SESSION data
«
Reply #8 on:
December 01, 2010, 02:27:40 PM »
register_globals is on.
«
Last Edit: December 01, 2010, 02:30:34 PM by CygnusX
»
Logged
Lords of Midnight
Nox
Level 35
Posts: 767
Reputation: +12/-2
Re: Losing PHP $_SESSION data
«
Reply #9 on:
December 01, 2010, 02:49:36 PM »
Yea, headshot... register_globals is meh thing... basicly exports $_(SESSION|POST|GET|...) so $_SESSION["Item"] is availible as $Item... same for all others, creating total mess. As you can see,
http://php.net/manual/en/security.globals.php
it's already deprecated, will probably be removed
Logged
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366
(a must-watch) | Join
BOINC
- no longer a hype, but you can help never the less
CygnusX
Level 24
Posts: 303
Reputation: +3/-2
Re: Losing PHP $_SESSION data
«
Reply #10 on:
December 01, 2010, 03:04:18 PM »
That makes sense. When I went back and did a foreach($_SESSION['Item'] as $Key => $Value) to dig into what was happening, it listed everything in $Item, which seemed completely out of left field.
I guess register_globals must work in both directions then; letting $_SESSION['Item'] overwrite $Item, and vice versa. I can't believe in 6 years this is the first time I've come across this problem. Either that, or my server has changed settings. Very very weird.
Logged
Lords of Midnight
Print
Pages: [
1
]
Go Up
« previous
next »
BBGameZone.net
»
Webmasters
»
Coding Discussion
»
Code Help
»
Losing PHP $_SESSION data
SimplePortal 2.3.3 © 2008-2010, SimplePortal