如何在PHP中将多维数组作为GET参数传递?

时间:2021-03-28 21:27:46

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?

当我用响应调用头文件时,文件将停止执行,但我在控制台中没有错误......我想也许这个数组需要为url编码?

if that is the case how?

如果是这样的话怎么样?

Thank you

2 个解决方案

#1


2  

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.

如果$ response是一个多维数组,你可以通过序列化()和urlencode()结果来获得最佳效果。它增加了一些开销,但不是太多。

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

但是,通过GET传输数据非常有限。数据量不应超过1-2千字节。来源:例如这里

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.

如果您的数据可能超过该限制,您应该考虑通过POST传输数据,或者如果不可能,则考虑在会话或其他类型的持久存储中传输数据。

#2


2  

Use http_build_query()

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

#1


2  

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.

如果$ response是一个多维数组,你可以通过序列化()和urlencode()结果来获得最佳效果。它增加了一些开销,但不是太多。

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

但是,通过GET传输数据非常有限。数据量不应超过1-2千字节。来源:例如这里

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.

如果您的数据可能超过该限制,您应该考虑通过POST传输数据,或者如果不可能,则考虑在会话或其他类型的持久存储中传输数据。

#2


2  

Use http_build_query()

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