RE: [PHP] Session data getting lost
* Thus wrote Rich Gray ([EMAIL PROTECTED]): Well a functon that doesn't work under certain conditions should be deprecated IMO ... I haven't used it for a long time now... this makes absolutly no sense. So if I use a function improperly, it should become deprecated? Er ...I'm not using it improperly I'm just not using it at all. Why? Because it behaves differently in different operating conditions. Sure I could write extra code to detect the operating conditions but what's the point? If globals are off you can't use it as it doesn't work... The manual seems to make it pretty obvious to me that it should be avoided and even mentions the function is deprecated in a code example... session_register() is used in cases where you haver register_globals on; it is not useed when it is off. So are you happy to use session_register() in your code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
* Thus wrote Rich Gray ([EMAIL PROTECTED]): So your telling me that all variables defined in the global scope are automatically added to the $_SESSION array...? Not true I think no. read the documentation, in full. you're right - I'm sorry I hadn't read it in full... The soluction to your problem was resolved from the first reply (by Chris Shiflett), but you rejected it because of it not making sense to you, which seems to be the problem. Yes, however I was simply asking Chris to explain to me more as it didn't make sense to me (because I hadn't read the manual fully). I mistakenly expected the $_SESSION array to hold copies of assigned data not references to the global namespace variable ... my expectations were based on PHP's current default behaviour of pass by copy rather than by reference. It seems with globals on it can become a minefield eg below where a script happens to define and use a variable with the same name as an entry in the $_SESSION array... ? // script_a.php - developed by dev A session_start(); $_SESSION['test'] = 'dev A saves some data'; header('Location : script_b.php'); ? ? // script_b.php - developed by dev B session_start(); $test = 'I am another variable in the global scope that happens to have the same name as a $_SESSION array entry'; print_r($_SESSION); // dev B has just trashed dev A's saved data... ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session data getting lost
Hi, Rich Gray [EMAIL PROTECTED] wrote: Well a functon that doesn't work under certain conditions should be deprecated IMO Interesting comment... However, there are TONS of functions that wouldn't work unless the module/extension were enabled during compilation/runtime. A couple of examples: http://www.php.net/xslt http://www.php.net/mbstring So, just because *those* functions don't work on certain conditions doesn't mean they should be deprecated. ;) Or, maybe I just missed your point :) - E - ...[snip]... __ Do You Yahoo!? Yahoo! BB is Broadband by Yahoo! http://bb.yahoo.co.jp/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
You have to put session_start(); at the VERY TOP of your code. even before alle the html tags. Hope that helps! Jan -Original Message- From: Chris Shiflett [mailto:[EMAIL PROTECTED] Sent: Dienstag, 16. September 2003 20:17 To: Rich Gray; [EMAIL PROTECTED] Php. Net Subject: Re: [PHP] Session data getting lost --- Rich Gray [EMAIL PROTECTED] wrote: I'm running v4.2.3 on RedHat v7.0 and am getting some strange behaviour with the $_SESSION superglobal... ... It works fine on Win2K albeit v4.3.0 of PHP. Maybe you have register_globals enabled on your Linux server and not on your Windows PC? Compare php.ini files before giving it too much thought. Chris = Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
Chris Thanks for your answer which I'm sorry to say makes no sense to me given the code example I supplied ... can you explain to me why you think register globals being set to on for the Linux server will cause the $_SESSION superglobal array to lose data? Am I missing something obvious here? Thx Rich --- Rich Gray [EMAIL PROTECTED] wrote: I'm running v4.2.3 on RedHat v7.0 and am getting some strange behaviour with the $_SESSION superglobal... ... It works fine on Win2K albeit v4.3.0 of PHP. Maybe you have register_globals enabled on your Linux server and not on your Windows PC? Compare php.ini files before giving it too much thought. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
Jan Sorry - no that doesn't help - as you can see from the code snippet I posted the session_start() is at the very top of the code... Thx anyway. Rich You have to put session_start(); at the VERY TOP of your code. even before alle the html tags. Hope that helps! Jan --- Rich Gray [EMAIL PROTECTED] wrote: I'm running v4.2.3 on RedHat v7.0 and am getting some strange behaviour with the $_SESSION superglobal... ... It works fine on Win2K albeit v4.3.0 of PHP. Maybe you have register_globals enabled on your Linux server and not on your Windows PC? Compare php.ini files before giving it too much thought. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
[snip] ?php session_start(); $test = -1; . [/snip] I think you need to register test http://us3.php.net/session_register HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
Jay Thanks, but no I don't think so ... session_register() is deprecated ... Quote PHP manual: Caution: If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled. Cheers Rich [snip] ?php session_start(); $test = -1; . [/snip] I think you need to register test http://us3.php.net/session_register HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
[snip] Thanks, but no I don't think so ... session_register() is deprecated ... [/snip] Not depricated, just doesn't work when register_globals is off in the .ini Have you done a print_r($_SESSION) to see if in fact the $test variable is contained? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
Well a functon that doesn't work under certain conditions should be deprecated IMO ... I haven't used it for a long time now... To answer your question ... yep I've used print_r() and after the 1st form submission the entry is set to -1 however at no time do I ever set $_SESSION['test'] to -1 in my code example ... Rich [snip] Thanks, but no I don't think so ... session_register() is deprecated ... [/snip] Not depricated, just doesn't work when register_globals is off in the .ini Have you done a print_r($_SESSION) to see if in fact the $test variable is contained? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
[snip] Well a functon that doesn't work under certain conditions should be deprecated IMO ... I haven't used it for a long time now... To answer your question ... yep I've used print_r() and after the 1st form submission the entry is set to -1 however at no time do I ever set $_SESSION['test'] to -1 in my code example ... [/snip] Nope, but $test is a GLOBAL variable, and therefore would be set to -1 within $_SESSION as all GLOBALS are, as you pointed out earlier, registerd with $_SESSION. If $test is within a function it is a PRIVATE variable, local to the function only, unless declared as a GLOBAL. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
So your telling me that all variables defined in the global scope are automatically added to the $_SESSION array...? Not true I think [snip] Well a functon that doesn't work under certain conditions should be deprecated IMO ... I haven't used it for a long time now... To answer your question ... yep I've used print_r() and after the 1st form submission the entry is set to -1 however at no time do I ever set $_SESSION['test'] to -1 in my code example ... [/snip] Nope, but $test is a GLOBAL variable, and therefore would be set to -1 within $_SESSION as all GLOBALS are, as you pointed out earlier, registerd with $_SESSION. If $test is within a function it is a PRIVATE variable, local to the function only, unless declared as a GLOBAL. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session data getting lost
* Thus wrote Rich Gray ([EMAIL PROTECTED]): Chris Thanks for your answer which I'm sorry to say makes no sense to me given the code example I supplied ... can you explain to me why you think register globals being set to on for the Linux server will cause the $_SESSION superglobal array to lose data? Am I missing something obvious here? This makes perfect sense (see below for what makes sense since you top posted.) This is all explained if you read the session documentation. http://php.net/session snip for the lazy If register_globals is enabled, then the global variables and the $_SESSION entries will automatically reference the same values which were registered in the prior session instance. /snip --- Rich Gray [EMAIL PROTECTED] wrote: I'm running v4.2.3 on RedHat v7.0 and am getting some strange behaviour with the $_SESSION superglobal... ... It works fine on Win2K albeit v4.3.0 of PHP. Maybe you have register_globals enabled on your Linux server and not on your Windows PC? Compare php.ini files before giving it too much thought. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session data getting lost
[snip] So your telling me that all variables defined in the global scope are automatically added to the $_SESSION array...? Not true I think [/snip] You're right of course. I went back to your original code and stripped it back some ?php session_start(); $test = -1; echo $_SESSION['test'].\n; $test = 999; $_SESSION['test'] = $test; echo $_SESSION['test'].\n; ? The logic is incorrect, when you reload the page $test gets set to -1 before your echo statement. After your echo statement it gets set to 999. On reload it again gets set to -1 before your echo. The second echo is always right (for what you want). If you comment out $test = -1; both echos come back correctly. Since you have declared $_SESSION['test'] once and the session is still in effect on the reload the first echo comes back -1 since that is what the declared variable is now worth. Make sense? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session data getting lost
* Thus wrote Rich Gray ([EMAIL PROTECTED]): So your telling me that all variables defined in the global scope are automatically added to the $_SESSION array...? Not true I think no. read the documentation, in full. The soluction to your problem was resolved from the first reply (by Chris Shiflett), but you rejected it because of it not making sense to you, which seems to be the problem. [snip] Well a functon that doesn't work under certain conditions should be deprecated IMO ... I haven't used it for a long time now... To answer your question ... yep I've used print_r() and after the 1st form submission the entry is set to -1 however at no time do I ever set $_SESSION['test'] to -1 in my code example ... [/snip] Nope, but $test is a GLOBAL variable, and therefore would be set to -1 within $_SESSION as all GLOBALS are, as you pointed out earlier, registerd with $_SESSION. If $test is within a function it is a PRIVATE variable, local to the function only, unless declared as a GLOBAL. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session data getting lost
* Thus wrote Rich Gray ([EMAIL PROTECTED]): Well a functon that doesn't work under certain conditions should be deprecated IMO ... I haven't used it for a long time now... this makes absolutly no sense. So if I use a function improperly, it should become deprecated? session_register() is used in cases where you haver register_globals on; it is not useed when it is off. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session data getting lost
--- Rich Gray [EMAIL PROTECTED] wrote: I'm running v4.2.3 on RedHat v7.0 and am getting some strange behaviour with the $_SESSION superglobal... ... It works fine on Win2K albeit v4.3.0 of PHP. Maybe you have register_globals enabled on your Linux server and not on your Windows PC? Compare php.ini files before giving it too much thought. Chris = Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php