Re: Re: POST-ing or GET-ing an array
| From: | Sascha Cunz | Date: | Tue, 29 Oct 2002 21:14:47 +0000 |
| Subject: | Re: Re: POST-ing or GET-ing an array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-121949@lists.php.net to get a copy of this message | ||
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