PHP - 如何发送一个阵列到另一个页面? [英] PHP - How to send an array to another page?

查看:93
本文介绍了PHP - 如何发送一个阵列到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个数组发送到另一个页面。

I'm trying to send an array to another page.

什么我trye​​d之前曾是:

What I tryed before was:

第1页

<input type='hidden' name='input_name' value='<?php print_r($array_name); ?>' />

和第2页

<?php 
$passed_array = $_POST['input_name'];
?>

现在我怎么做 $ passed_array 像数组?

或者你知道的解决这一问题的任何其他方式?

Or do you know of any other way of solving this problem?

谢谢,迈克。

编辑:我想要做这种方式的原因是因为我需要避免会议和饼干

The reason I want to do it this way is because I need to avoid sessions and cookies.

推荐答案

您可以把它放在会话:

session_start();
$_SESSION['array_name'] = $array_name;

或者,如果你想通过一个表格发送它,你可以序列吧:

<input type='hidden' name='input_name' value="<?php echo htmlentities(serialize($array_name)); ?>" />

$passed_array = unserialize($_POST['input_name']);

会话的优点是客户端没有看到它(因此不能乱动),如果阵列是大它的速度更快。它的缺点是它可能会感到困惑,如果用户有多个选项卡中打开。

The session has the advantage that the client doesn't see it (therefore can't tamper with it) and it's faster if the array is large. The disadvantage is it could get confused if the user has multiple tabs open.

编辑:很多答案都在使用提示 NAME =input_name []。这不会在一般情况下工作 - 这将需要进行修改以支持关联数组,并修改了很多支持多维数组(恶心!)。好多坚持序列化。

a lot of answers are suggesting using name="input_name[]". This won't work in the general case - it would need to be modified to support associative arrays, and modified a lot to support multidimensional arrays (icky!). Much better to stick to serialize.

这篇关于PHP - 如何发送一个阵列到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆