How do I Pass a PHP Array to Another Page

I’m creating a array in php on one page and want to pass all occurances of the array to another page using the <a> tag. Can someone tell me how to do this. Thanks.

Hi,

Try this:


$data = serialize( $array );
echo "<a href='/page.php?data=$data'>Go To Page</a>";

then to get the info back use:


$array = unserialize( $data );

Don’t think that is gonna work you mave to use a from and make a hidden input and then submit the form somehow.

True, it does depend on the aray not storing huge amounts of data. The other option is to use PHPs session functions and store the serilized array in a session variable.

I tried the serialize() aproach but the serialized string contains more than one character that the browser does not like in a query string, I think sessions would be the best way to go

I thought I would be able to reference all occurances of an array and be able to pass that variable. Mabye I should make the call again on the new page. I was just trying to avoid the call since I already had the information from a call in the first page.

Sorry I took so long to respond. I tried using serialize last night and it didn’t work as Freddy stated.

I started looking into Sessions and it seems complex, more complex than what i’m trying to accomplish here.

Any thoughts?

Sessions aren’t that complex really, and if you figure out how to do them you’ll find loads of usedul applications. The only downside is that session data won’t be passed on if your user doesn’t have cookies turned on (unless it’s possible to extract the session id and pass it in an <a href> tag - that should work theoretically but I’ve never seen it done…)

Check out these tutorials:

http://www.phpwizard.net/resources/tutorials/session_intro.html

http://www.php.net/manual/en/ref.session.php (PHP Manual)

Thanks Skunk. I’ll check out the links.

An alternative to using serialize()/unserialize with sessions is to use implode()/explode(), eg:

$session_var=implode(“|”,$array);
$array=explode(“|”,$session_var);

Make sure you’ve got your session set up properly first, of course. My approach might have benefits over serialize() because it seems if you want to serialise(), the you have to worry about urlencode() etc. (see: http://www.php.net/manual/en/function.serialize.php)