That is what serialize() is for. $my_array[0] = 'hello'; $my_serialized_array = serialize($my_array); header ("Location: http://www.url.ext/file.php?array=$my_serialized_array"); PHP:
So serialize() is like a zip file only it contains variables...nice! So it's gonna be like this? //in page 1 $myarray[] = "Sonic"; $myarray[] = "Mario"; $myarray[] = "Linus Torvalds"; $myarray[] = "Contra"; $serializeme = serialize($myarray); header ("Location: http://www.url.ext/file.php?getme=$serializeme"); //passes the array to page 2 $gotit = $_GET['getme']; $var = unserialize($gotit); echo count($var); //should return 4 PHP: Right?
serialize() is not meant for that, even if it might be possible. (urlencode() would still be necessary) You can pass arrays via URL like this. header ("Location: http://www.url.ext/file.php?getme[]=Sonic&getme[]=Mario&getme[]=Linus"); PHP: You can also give the array specific keys. header ("Location: http://www.url.ext/file.php?getme[foo]=Sonic&getme[foo]=Mario&getme[bar]=Linus"); PHP:
I get it. I have another question, how would a hidden form work with this? I've never used one before so in short, I have no idea what I'm talking about. hehehe... is it even related to this post?
Same as normal fields. Hidden fields are ONLY hidden in the HTML form.. for the user's view. You cannot hide them in the URL. But you could use POST method instead.
I'm not understanding how to send the array to another page. My first page has a form that sends an array (named $table) of states to a results page. The array should look like this: [0] => AKrpt [1] => AZrpt [2] => CArpt [3] => IDrpt [4] => ORrpt The results are printed in text format, but there is a link to map the results. A new query is run on this third page to map the results, but the query needs the array passed to it from the second page, preferably in the link. During the testing process, I have just been sending one option, so an array with only one key, for simplicity. I have been searching how to pass an array through a url and see there are issues with it. I have seen where sessions are recommended. I haven't been able to see an example of it working. Here is some of my code: This is the link on the second page to page 3: $table = $_REQUEST['table']; $table_serialized = serialize($table); ?> <? echo "<li><a href=\"http://nwham.com/repeaters/map_multi.php?table=$table_serialized\" target='_top'\">Map</a></li>\n"; ?> PHP: On the third page I have tried to unserialize the array: $table = $_REQUEST['table']; $table = unserialize($serialized_table); PHP: But the link looks like this: http://nwham.com/repeaters/map_multi.php?table=a:1:{i:0;s:5: and of course, fails.
I am trying it like this, too <? echo "<li><a href=\"http://nwham.com/repeaters/map_multi.php?table=urlencode($table)\" target='_top'\">Map</a></li>\n"; ?> PHP: But the URL looks like this: http://nwham.com/repeaters/map_multi.php?table=urlencode(Array) Which probably means I have no idea what I am doing or how to do it?
I just need a simple example of how to encode() the array into a url. I am now trying: <? $table = urlencode($table) ?> <? echo "<li><a href=\"http://nwham.com/repeaters/map_multi.php?table=$table\" target='_top'\">Map</a></li>\n"; ?> PHP: and am getting: Warning: urlencode() expects parameter 1 to be string, array given in.... Can someone just show me a quick example to pass the array?