通过PHP头重定向发送数组

通过PHP头重定向发送数组,php,arrays,redirect,Php,Arrays,Redirect,基本上,我需要一些帮助,通过PHP中的重定向发送数组信息。我有以下代码: Page1:我创建了查询字符串并将其发送到第2页,我可以在第2页上获取$\u get中的数据 $qstr = http_build_query( array( 'products_array' => $products, 'quantity' => $_POST['quantity'] ) ); heade

基本上,我需要一些帮助,通过PHP中的重定向发送数组信息。我有以下代码:

Page1:我创建了查询字符串并将其发送到第2页,我可以在第2页上获取$\u get中的数据

    $qstr = http_build_query(
        array(
            'products_array' => $products,
            'quantity' => $_POST['quantity']
        )
    );

    header('Location: registration.php?' . $qstr);
第2/3页我从$\u服务器获取查询字符串,并将其与重定向页面连接起来

header('Location: login.php?' . $_SERVER['QUERY_STRING']);
我可以使用普通href链接发送数据,但如果我尝试像上面那样发送数据,我无法检索第2页之后的数据

如果你能在这个问题上给我一些建议,我会很有帮助的

谢谢

编辑: 回声$qtystr给出:

products_array%5B0%5D%5Bitem%5D=http%3A%2F%2Fecx.images amazon.com%2FI%2F61Y-rF9tF8L.SL1100.jpg和products_array%5B0%5D%5Bbrand%5D=Charmander和products_array%5B0%5D%5D=25和products_array%5B1%5B1%5D%5b%5b%5D=http%3A%2F%2Fecx.images amazon.com%2Fimages%2FI%2FI%2FI%2FI%2FI%2FI%2FI%2FI%2FI%2F61vgC3GDI2L.SL1100.jpg和products_%5D%5b%%5B1%5D%5B价格%5D=15和产品数组%5B2%5D%5B价格%5D=http%3A%2F%2Fecx.images亚马逊网站%2FI%2F51TnHKT4oML.SY300.jpg和产品数组%5B2%5D%5B品牌%5D=Bulbasaur和产品数组%5B2%5D%5B价格%5D=10和产品数组%5B3%5B%5D%5B项目%5D=http%3A%2FI%2FE%2Fecx.images亚马逊网站%2FI%2FI品牌数组%2FI%2FI产品数组%5BZHOL产品数组%5B300.JPta&products_array%5B3%5D%5Bprice%5D=20&products_array%5B4%5D%5B物品%5D=http%3A%2F%2Fecx.images amazon.com%2Fimages%2FI%2F51BIJR%252BIqDL.SX355.jpg&products_array%5B4%5D=Mudkip&products_array%5B4%5D%5B价格%5D%5D%5D=20&quantity%5B0%5B0%5B1%5D=0&quantity%5B1%5Dd=0&quantity%5B3%5B3%5B03%5B4%

这是一个愚蠢的信息量传递在一个字符串(只是测试出来的东西),对不起,但这是所有的信息从两个数组我需要的

编辑2:

我设法解决了,我没有给你们足够的信息抱歉。问题实际上是我没有设置页面的表单操作来保留数据字符串,因此在处理表单时它一直丢失。感谢所有的建议,我下次一定会尝试,尤其是会话。

只使用PHP 对数据进行编码

$products = "some product";
$qtd = 1;
$array = array('products_array' => $products, 'quantity' => $qtd);
$json_str = json_encode($array);
echo $json_str;
header('Location: registration.php?' . $qstr);
$data = json_decode($post_data); //to decode the string into an object
echo $data->products_array . "\r\n";
echo $data->quantity . "\r\n";
解码数据

$products = "some product";
$qtd = 1;
$array = array('products_array' => $products, 'quantity' => $qtd);
$json_str = json_encode($array);
echo $json_str;
header('Location: registration.php?' . $qstr);
$data = json_decode($post_data); //to decode the string into an object
echo $data->products_array . "\r\n";
echo $data->quantity . "\r\n";

您可以将信息存储在会话中,它比在url中传递要干净一点。在使用页眉之前,请在页面本身中通过echo$qstr检查。我认为在生成数组时存在一些问题。如果使用url_编码的json字符串传递信息,我认为使用PHP或Javascript进行编码和解码会更简单,即使考虑到传递大(>512字节)通过头的数据量是一个坏主意,使用会话或数据库。