RE: [PHP] Re: POST-ing or GET-ing an array

From: Date: Tue, 29 Oct 2002 21:12:47 +0000
Subject: RE: [PHP] Re: POST-ing or GET-ing an array
Groups: php.general 
Request: Send a blank email to php-general+get-121950@lists.php.net to get a copy of this message
You need to call start_session before accessing $_SESSION variables UNLESS you have PHP configured to automatically start_session (which is off by default). You need to start_sesion so that scripts that don't need $_SESSION don't go through the overhead of starting session. Jason -----Original Message----- From: Sascha Cunz [mailto:Sascha@GaNoAn.org] Sent: Tuesday, October 29, 2002 2:15 PM To: Nick Eby; php-general@lists.php.net Subject: Re: [PHP] Re: POST-ing or GET-ing an array Hi, > I disagree that serialize/unserialize is the way to go, unless you're > absolutely completely sure that there will only be a relatively small > number of things in the array. As somebody mentioned briefly, the get > request is limited to a certain number of bytes, and the string > representing your serialized array could easily get too large to send on a > get request. > > imho the best option is to use the session, which somebody already > mentioned but didn't really elaborate... > $_SESSION['my_array'] = $my_array; Exactly. But just to mention it at this point: if you have script-output (echo, print, print_r etc.) before any operation on $_SESSION, you should call start_session() at the start of the script. (I don't know if recent versions of PHP still _need_ this) > > and on next_page (or any other page), you'd just use $_SESSION['my_array'] > where you need. I would suggest, unsetting the array in the next_page (or whatever) after you don't need it anymore: unset($_SESSION['my_array']); > Another option would be to send the request as a post, and > serialize the array into a hidden variable in your form; that way you won't > have to worry (as much) about size constraints. (a post request is also > limited in size, but it's so large that you probably would never approach > the limit.) > > /nick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#121950) next »