Re: [PHP] Re: SESSION array problems
Micah Gersten wrote: You really should get up to speed on PHP 5. Micah Gersten wrote: I was referring to Nathan's examples which you cut out of the post. function save_to_session( ) { global $userids , $first , $last; $_SESSION['user_id'] = $userids; $_SESSION['first_name'] = $first; $_SESSION['last_name']= $last; } ahh I thought that but didn't want to assume; I am actually strictly PHP5.2+/OO and flat out refuse to use globals (preference to static class variables), and keep session usage to a minimum. However the example I gave tedd was the only way in which I could create code to replicate his error (explaining the passing a variable by reference to session, the redefining of that referenced array as a string within the for loop and so on). This actually turned out to be register globals turned on; however it's been so dang long since I used them, (and indeed anything pre-php5), that I forget register globals even existed; thus replicated it's functionality. [lol] Regards! -- nathan ( [EMAIL PROTECTED] ) { Senior Web Developer php + java + flex + xmpp + xml + ecmascript web development edinburgh | http://kraya.co.uk/ } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
On Thu, Oct 2, 2008 at 10:37 AM, tedd [EMAIL PROTECTED] wrote: To all: The code provided by nathan works for me as well. However, the problem is not easily explained, but I can demonstrate it -- try this: http://www.webbytedd.com/zzz/index.php * A complete listing of the code follows the demo. When the code is first loaded, the session variables are defined and populated. Proof of this is shown in the top left corner of the page, which reports: Cable Diane Ron Big Dirt Joe Now click the Continue button and you will be presented with the next step which shows a list of the SESSION variables in both the top left corner AND immediately below Step 2. Everything is righteous to there. However, the next portion of the code is the foreach loop where the first SESSION pair is output correctly, but the rest aren't. This is followed by another listing of the SESSION variables and this time is shows that they have completely disappeared. Okay gang -- what's up with that? Cut and paste the code and see for yourself. Cheers, tedd tedd, Is there any chance that session variables are getting auto registered? The fact that the second time through the loop is outputting the second letter of each name looks like $first_name is bound to $_SESSION['first_name'] and $last_name is bound to $_SESSION['last_name']. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
tedd wrote: At 11:10 PM +0100 10/1/08, Nathan Rixham wrote: [tested - works] -snip- ? regards! nathan :) I need to re-address this.. tedd your original code works fine over here; as does the code I sent you, and the code jay submitted first.. do us a favour, copy and paste exactly what I just handed through and run it; are the results correct? To all: The code provided by nathan works for me as well. However, the problem is not easily explained, but I can demonstrate it -- try this: http://www.webbytedd.com/zzz/index.php * A complete listing of the code follows the demo. When the code is first loaded, the session variables are defined and populated. Proof of this is shown in the top left corner of the page, which reports: Cable Diane Ron Big Dirt Joe Now click the Continue button and you will be presented with the next step which shows a list of the SESSION variables in both the top left corner AND immediately below Step 2. Everything is righteous to there. However, the next portion of the code is the foreach loop where the first SESSION pair is output correctly, but the rest aren't. This is followed by another listing of the SESSION variables and this time is shows that they have completely disappeared. Okay gang -- what's up with that? Cut and paste the code and see for yourself. Cheers, tedd Much as it pains me to ask this, you don't have REGISTER_GLOBALS on, do you? Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
Jay Moore wrote: tedd wrote: At 11:10 PM +0100 10/1/08, Nathan Rixham wrote: [tested - works] -snip- ? regards! nathan :) I need to re-address this.. tedd your original code works fine over here; as does the code I sent you, and the code jay submitted first.. do us a favour, copy and paste exactly what I just handed through and run it; are the results correct? To all: The code provided by nathan works for me as well. However, the problem is not easily explained, but I can demonstrate it -- try this: http://www.webbytedd.com/zzz/index.php * A complete listing of the code follows the demo. When the code is first loaded, the session variables are defined and populated. Proof of this is shown in the top left corner of the page, which reports: Cable Diane Ron Big Dirt Joe Now click the Continue button and you will be presented with the next step which shows a list of the SESSION variables in both the top left corner AND immediately below Step 2. Everything is righteous to there. However, the next portion of the code is the foreach loop where the first SESSION pair is output correctly, but the rest aren't. This is followed by another listing of the SESSION variables and this time is shows that they have completely disappeared. Okay gang -- what's up with that? Cut and paste the code and see for yourself. Cheers, tedd Much as it pains me to ask this, you don't have REGISTER_GLOBALS on, do you? Jay Try these options (separately): 1) Change your first and third entries (so Joe Dirt is 0 and Cable Diane is 2). See if your 2nd output is now '1 o i'. 2) Change your storage variables ($first_name and $last_name) to something other than the key values of your session array (ex: $fname and $lname). See if that works. Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
Much as it pains me to ask this, you don't have REGISTER_GLOBALS on, do you? Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It must be. I just ran tedd's example in both scenarios. With register_globals = Off it works like a charm. With register_globals = On I get the same output tedd does. register_globals = on: Problem Step 2 -- Cable Diane Ron Big Dirt Joe 0 Cable Diane 1 a i 2 register_globals = Off: Step 2 -- Cable Diane Ron Big Dirt Joe 0 Cable Diane 1 Ron Big 2 Dirt Joe Cable Diane Ron Big Dirt Joe -- Thiago Henrique Pojda Forgot my blog url, php list doesn't like it :) -- Thiago Henrique Pojda Okay, gmail must be playing with me... 3rd email rejected by spammy url -- Thiago Henrique Pojda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
Andrew Ballard wrote: On Thu, Oct 2, 2008 at 10:37 AM, tedd [EMAIL PROTECTED] wrote: To all: The code provided by nathan works for me as well. However, the problem is not easily explained, but I can demonstrate it -- try this: http://www.webbytedd.com/zzz/index.php * A complete listing of the code follows the demo. When the code is first loaded, the session variables are defined and populated. Proof of this is shown in the top left corner of the page, which reports: Cable Diane Ron Big Dirt Joe Now click the Continue button and you will be presented with the next step which shows a list of the SESSION variables in both the top left corner AND immediately below Step 2. Everything is righteous to there. However, the next portion of the code is the foreach loop where the first SESSION pair is output correctly, but the rest aren't. This is followed by another listing of the SESSION variables and this time is shows that they have completely disappeared. Okay gang -- what's up with that? Cut and paste the code and see for yourself. Cheers, tedd tedd, could you please in foreach loop (on your website) add one echo line: foreach( $_SESSION['user_id'] as $index = $value ) { echo '- '.$index.': '.$value.'br'; $last_name = $_SESSION['last_name'][$index]; $first_name = $_SESSION['first_name'][$index]; echo(p$index $last_name $first_name/p); } thanks -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
tedd wrote: At 11:10 PM +0100 10/1/08, Nathan Rixham wrote: [tested - works] -snip- ? regards! nathan :) I need to re-address this.. tedd your original code works fine over here; as does the code I sent you, and the code jay submitted first.. do us a favour, copy and paste exactly what I just handed through and run it; are the results correct? To all: The code provided by nathan works for me as well. However, the problem is not easily explained, but I can demonstrate it -- try this: http://www.webbytedd.com/zzz/index.php * A complete listing of the code follows the demo. When the code is first loaded, the session variables are defined and populated. Proof of this is shown in the top left corner of the page, which reports: Cable Diane Ron Big Dirt Joe Now click the Continue button and you will be presented with the next step which shows a list of the SESSION variables in both the top left corner AND immediately below Step 2. Everything is righteous to there. However, the next portion of the code is the foreach loop where the first SESSION pair is output correctly, but the rest aren't. This is followed by another listing of the SESSION variables and this time is shows that they have completely disappeared. Okay gang -- what's up with that? Cut and paste the code and see for yourself. Cheers, tedd Well, I would have to say it is a configuration issue on your server. Here is the results for my test with your code. Works fine. http://www.cmsws.com/examples/php/testscripts/[EMAIL PROTECTED]/002.php -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
Jim Lucas wrote: tedd wrote: At 11:10 PM +0100 10/1/08, Nathan Rixham wrote: [tested - works] -snip- ? regards! nathan :) I need to re-address this.. tedd your original code works fine over here; as does the code I sent you, and the code jay submitted first.. do us a favour, copy and paste exactly what I just handed through and run it; are the results correct? To all: The code provided by nathan works for me as well. However, the problem is not easily explained, but I can demonstrate it -- try this: http://www.webbytedd.com/zzz/index.php * A complete listing of the code follows the demo. When the code is first loaded, the session variables are defined and populated. Proof of this is shown in the top left corner of the page, which reports: Cable Diane Ron Big Dirt Joe Now click the Continue button and you will be presented with the next step which shows a list of the SESSION variables in both the top left corner AND immediately below Step 2. Everything is righteous to there. However, the next portion of the code is the foreach loop where the first SESSION pair is output correctly, but the rest aren't. This is followed by another listing of the SESSION variables and this time is shows that they have completely disappeared. Okay gang -- what's up with that? Cut and paste the code and see for yourself. Cheers, tedd Well, I would have to say it is a configuration issue on your server. Here is the results for my test with your code. Works fine. http://www.cmsws.com/examples/php/testscripts/[EMAIL PROTECTED]/002.php With RG off, it works as expected. But, with RG on it gives the results he was seeing. -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems UPDATE
Jim Lucas wrote: Jim Lucas wrote: tedd wrote: At 11:10 PM +0100 10/1/08, Nathan Rixham wrote: [tested - works] -snip- ? regards! nathan :) I need to re-address this.. tedd your original code works fine over here; as does the code I sent you, and the code jay submitted first.. do us a favour, copy and paste exactly what I just handed through and run it; are the results correct? To all: The code provided by nathan works for me as well. However, the problem is not easily explained, but I can demonstrate it -- try this: http://www.webbytedd.com/zzz/index.php * A complete listing of the code follows the demo. When the code is first loaded, the session variables are defined and populated. Proof of this is shown in the top left corner of the page, which reports: Cable Diane Ron Big Dirt Joe Now click the Continue button and you will be presented with the next step which shows a list of the SESSION variables in both the top left corner AND immediately below Step 2. Everything is righteous to there. However, the next portion of the code is the foreach loop where the first SESSION pair is output correctly, but the rest aren't. This is followed by another listing of the SESSION variables and this time is shows that they have completely disappeared. Okay gang -- what's up with that? Cut and paste the code and see for yourself. Cheers, tedd Well, I would have to say it is a configuration issue on your server. Here is the results for my test with your code. Works fine. http://www.cmsws.com/examples/php/testscripts/[EMAIL PROTECTED]/002.php With RG off, it works as expected. But, with RG on it gives the results he was seeing. that explains my earlier post on the matter: in this case.. what's happened is: $_SESSION['first_name'] is a reference to a variable $first (or whatever is in your for loop) $_SESSION['last_name'] is a reference to a variable $last (or whatever is in your for loop) when you've set $last and $first to string's in the for loop it's passed the variable by reference back to $_SESSION['first_name'] and $_SESSION['last_name'] as strings; when it hit's the second iteration on the for loop it now has strings to deal with so uses the $key (holding integer 1 at this stage) as a string offset thus giving you the second character (offset [1]) of the string variables $last/$first. now set to 'cable'/'diane' thus giving you the 'a'/'i'. when it does pass three there is no offset [2] so gives you nothing. *phew* reproduce code! ?php $userids = array('6156','1234','8867'); $first = array('Diane','Big','Joe'); $last = array('Cable','Ron','Dirt'); function save_to_session( ) { global $userids , $first , $last; $_SESSION['user_id'] = $userids; $_SESSION['first_name'] = $first; $_SESSION['last_name']= $last; } save_to_session( ); print_r( $_SESSION ); $num_users = count($_SESSION['user_id']); for ($i = 0; $i $num_users; $i++) { $first = $_SESSION['first_name'][$i]; $last = $_SESSION['last_name'][$i]; echo $last, $first\n; } ? lol to think ti was just register globals - thats why i don't use globals! ps: tedd; you could have got to the bottom of this earlier by having error reporting set to include notices :) -- nathan ( [EMAIL PROTECTED] ) { Senior Web Developer php + java + flex + xmpp + xml + ecmascript web development edinburgh | http://kraya.co.uk/ } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems
Nathan Rixham wrote: tedd wrote: At 3:41 PM -0400 10/1/08, tedd wrote: What about: foreach ($_SESSION['user_id'] as $key = $value) { $last = $_SESSION['last_name'][$key]; $first = $_SESSION['first_name'][$key]; echo $last, $first; } Jay: Close, it produced: Array, Array Array, Array Array, Array Cheers, tedd My error, if produced. Cable, Diane a, i While print_r($_SESSION); JUST BEFORE IT produced: [user_id] = Array ( [0] = 6156 [1] = 7030 [2] = 656 ) [first_name] = Array ( [0] = Diane [1] = first name [2] = Helen ) [last_name] = Array ( [0] = Cable [1] = CagoEsogs-temp (forum) [2] = Cahalane ) Now, what wrong with this picture? Cheers, tedd tedd wrote: At 3:41 PM -0400 10/1/08, tedd wrote: What about: foreach ($_SESSION['user_id'] as $key = $value) { $last = $_SESSION['last_name'][$key]; $first = $_SESSION['first_name'][$key]; echo $last, $first; } Jay: Close, it produced: Array, Array Array, Array Array, Array Cheers, tedd My error, if produced. Cable, Diane a, i While print_r($_SESSION); JUST BEFORE IT produced: [user_id] = Array ( [0] = 6156 [1] = 7030 [2] = 656 ) [first_name] = Array ( [0] = Diane [1] = first name [2] = Helen ) [last_name] = Array ( [0] = Cable [1] = CagoEsogs-temp (forum) [2] = Cahalane ) Now, what wrong with this picture? Cheers, tedd in this case.. what's happened is: $_SESSION['first_name'] is a reference to a variable $first (or whatever is in your for loop) $_SESSION['last_name'] is a reference to a variable $last (or whatever is in your for loop) when you've set $last and $first to string's in the for loop it's passed the variable by reference back to $_SESSION['first_name'] and $_SESSION['last_name'] as strings; when it hit's the second iteration on the for loop it now has strings to deal with so uses the $key (holding integer 1 at this stage) as a string offset thus giving you the second character (offset [1]) of the string variables $last/$first. now set to 'cable'/'diane' thus giving you the 'a'/'i'. when it does pass three there is no offset [2] so gives you nothing. *phew* reproduce code! ?php $userids = array('6156','1234','8867'); $first = array('Diane','Big','Joe'); $last = array('Cable','Ron','Dirt'); function save_to_session( ) { global $userids , $first , $last; $_SESSION['user_id'] = $userids; $_SESSION['first_name'] = $first; $_SESSION['last_name']= $last; } save_to_session( ); print_r( $_SESSION ); $num_users = count($_SESSION['user_id']); for ($i = 0; $i $num_users; $i++) { $first = $_SESSION['first_name'][$i]; $last = $_SESSION['last_name'][$i]; echo $last, $first\n; } ? Regards! This looks like a bug. If you are not modifying a variable with the same name as the session variable, it should not change the session variable. Also, why are you assigning references to arrays? What version of PHP are you using? You really should get up to speed on PHP 5. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems
At 11:14 AM -0500 10/2/08, Micah Gersten wrote: You really should get up to speed on PHP 5. Yeah, I'll be sure to tell me clients that. Sometimes you don't have a choice -- you have to work with what they got. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems
I was referring to Nathan's examples which you cut out of the post. function save_to_session( ) { global $userids , $first , $last; $_SESSION['user_id'] = $userids; $_SESSION['first_name'] = $first; $_SESSION['last_name']= $last; } Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com tedd wrote: At 11:14 AM -0500 10/2/08, Micah Gersten wrote: You really should get up to speed on PHP 5. Yeah, I'll be sure to tell me clients that. Sometimes you don't have a choice -- you have to work with what they got. Cheers, tedd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems
On Wed, 2008-10-01 at 15:41 -0400, tedd wrote: What about: foreach ($_SESSION['user_id'] as $key = $value) { $last = $_SESSION['last_name'][$key]; $first = $_SESSION['first_name'][$key]; echo $last, $first; } Jay: Close, it produced: Array, Array Array, Array Array, Array Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com That would suggest there's another level to the $_SESSION array. Are you sure the data output from the print_r is right and nothing is acting on it before your loop? Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems
tedd wrote: What about: foreach ($_SESSION['user_id'] as $key = $value) { $last = $_SESSION['last_name'][$key]; $first = $_SESSION['first_name'][$key]; echo $last, $first; } Jay: Close, it produced: Array, Array Array, Array Array, Array Cheers, tedd then your $_SESSION is not what you think it is and print_r() output is not correct. :-) -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: SESSION array problems
tedd wrote: At 3:41 PM -0400 10/1/08, tedd wrote: What about: foreach ($_SESSION['user_id'] as $key = $value) { $last = $_SESSION['last_name'][$key]; $first = $_SESSION['first_name'][$key]; echo $last, $first; } Jay: Close, it produced: Array, Array Array, Array Array, Array Cheers, tedd My error, if produced. Cable, Diane a, i While print_r($_SESSION); JUST BEFORE IT produced: [user_id] = Array ( [0] = 6156 [1] = 7030 [2] = 656 ) [first_name] = Array ( [0] = Diane [1] = first name [2] = Helen ) [last_name] = Array ( [0] = Cable [1] = CagoEsogs-temp (forum) [2] = Cahalane ) Now, what wrong with this picture? Cheers, tedd tedd wrote: At 3:41 PM -0400 10/1/08, tedd wrote: What about: foreach ($_SESSION['user_id'] as $key = $value) { $last = $_SESSION['last_name'][$key]; $first = $_SESSION['first_name'][$key]; echo $last, $first; } Jay: Close, it produced: Array, Array Array, Array Array, Array Cheers, tedd My error, if produced. Cable, Diane a, i While print_r($_SESSION); JUST BEFORE IT produced: [user_id] = Array ( [0] = 6156 [1] = 7030 [2] = 656 ) [first_name] = Array ( [0] = Diane [1] = first name [2] = Helen ) [last_name] = Array ( [0] = Cable [1] = CagoEsogs-temp (forum) [2] = Cahalane ) Now, what wrong with this picture? Cheers, tedd in this case.. what's happened is: $_SESSION['first_name'] is a reference to a variable $first (or whatever is in your for loop) $_SESSION['last_name'] is a reference to a variable $last (or whatever is in your for loop) when you've set $last and $first to string's in the for loop it's passed the variable by reference back to $_SESSION['first_name'] and $_SESSION['last_name'] as strings; when it hit's the second iteration on the for loop it now has strings to deal with so uses the $key (holding integer 1 at this stage) as a string offset thus giving you the second character (offset [1]) of the string variables $last/$first. now set to 'cable'/'diane' thus giving you the 'a'/'i'. when it does pass three there is no offset [2] so gives you nothing. *phew* reproduce code! ?php $userids = array('6156','1234','8867'); $first = array('Diane','Big','Joe'); $last = array('Cable','Ron','Dirt'); function save_to_session( ) { global $userids , $first , $last; $_SESSION['user_id'] = $userids; $_SESSION['first_name'] = $first; $_SESSION['last_name']= $last; } save_to_session( ); print_r( $_SESSION ); $num_users = count($_SESSION['user_id']); for ($i = 0; $i $num_users; $i++) { $first = $_SESSION['first_name'][$i]; $last = $_SESSION['last_name'][$i]; echo $last, $first\n; } ? Regards! -- nathan ( [EMAIL PROTECTED] ) { Senior Web Developer php + java + flex + xmpp + xml + ecmascript web development edinburgh | http://kraya.co.uk/ } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php