views:

126

answers:

2

I have the following code.

$connect  = new Connection ();
$response = $connect->putFile($fileName, $destination);
header("Location: /test.php?response=" . $response);

When I invoke header with the response, the file will stop execution, but I will have no error in the console... I am thinking maybe this array needs to be encoded for the url?

if that is the case how?

Thank you

+1  A: 

Use http_build_query()

http://us.php.net/http-build-query

awgy
I thought about using http_build_query, but the problem is that this will only turn every value of the array as get parameter. For a one dimensional array this may work well, but not for a multidimensional array, specially if the response is different every time or if it contains multiple arrays like this[0] => SimpleXMLElement Object ()[1] => SimpleXMLElement Object ()[2] => SimpleXMLElement Object ()[3] => SimpleXMLElement Object ()...
Onema
+1  A: 

If $response is a multi-dimensional array, you may fare best by serialize()ing it and urlencode() ing the result. It adds some overhead but not too much.

However, transporting data through GET is seriously limited. The amount of data should not exceed 1-2 kilobytes. Source: For example here

If your data is likely to exceed that limit, you should think about either transporting the data through POST or, if that's not possible, in a session or other kind of persistent storage.

Pekka