# Solved: Passing an array to a PHP program using the URL



## JiminSA (Dec 15, 2011)

I read this advice (via Google)


> You cannot pass an array through a url in it's raw form. You have to
> serialize it, encode it, then on the receiving page you unencode it, and finally unserialize it.


So I wrote this code in the sending program...

```
");
		$mode = 'edit';
		$tarray = $topic_array;
		$serialized = rawurlencode(serialize($tarray));
 		echo ("
		<a href=\"http://surf4wheels.biz/dev/adedit.php?topic_name=$topic&id_no=$keyno&mode=$mode&tarray=$serialized \" onclick=\"window.open('http://surf4wheels.biz/dev/adedit.php?topic_name=$topic&id_no=$keyno&mode=$mode&tarray=$serialized' ,'popup','width=1100,height=200,scrollbars=no,resizable=yes,toolbar=yes,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false\"><img src=\"edit.jpg\" style=\"position: relative; left: 1018px;\" border=\"1px\" border=\"1px\" solid; title=\"If this Ad. is yours, you can do Maintenance on it.\"></a>

		");
```
and this in the receiving program...

```
$topic_name = $_REQUEST["topic_name"];
	if (isset($topic_name))
		{
		$topic_array = unserialize(rawurldecode($_GET['tarray']));
echo "<pre>";
print_r($topic_array);
echo "</pre>";
		$pos = array_search($topic_name, $topic_array); 
		$topic_get = $pos;
		}
```
... Yes, you've guessed it! It's not grafting - it does nor recognise $topic_array as an array and giving me the following error message ...


> Warning: array_search() expects parameter 2 to be array, boolean given in /home/surfwhee/public_html/dev/adedit.php on line 134


Can anyone see where I'm going awry?? Because I can't...


----------



## allnodcoms (Jun 30, 2007)

Whenever I have to pass arrays about I use $_SESSION[] - way simpler!

Danny


----------



## allnodcoms (Jun 30, 2007)

Seriously though, I can't see a problem at the moment. Have you echoed out the results of serialize & unserialize?
Only other suggestion would be to try:

```
$topic_array = array(unserialize(rawurldecode($_GET['tarray']))); // load unserialized data into an array?
```
(or go with $_SESSION)

Danny


----------



## dukevyner (Nov 4, 2011)

I also find a $_session as the best way to pass an array


----------



## JiminSA (Dec 15, 2011)

I tried

```
$topic_array = array(unserialize(rawurldecode($_GET['tarray']))); // load unserialized data into an array?
```
and it now sees it as an array - but unfortunately an empty one!

As regards passing arrays via SESSION - won't my having utilised an href "popup" to get to my edit/delete routine (the array receiver, eventually I hope), take me out of the SESSION?? - Please forgive any apparent naivety, because it's not apparent - it's real! When it comes to PHP I am a self confessed juvenile! Hence bugging you guys every 5 minutes! (I have 3 weeks experience!)


----------



## JiminSA (Dec 15, 2011)

No matter - I've circumvented the problem by doing the work in the calling program...


----------

