PHP,通过POST传递数组 [英] PHP, pass array through POST

查看:245
本文介绍了PHP,通过POST传递数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是通过 POST

foreach ($id as $array)
{
<input type="hidden" name="prova[]" value="<?php echo $array; ?>"/>
}
<input type="submit" name="submit"/>

或使用破灭()以创建一个变量,传递变量,然后使用爆炸()来找回值到一个新的数组?

or using implode() to create a single variable, pass the variable and then use explode() to get back the values into a new array?

推荐答案

修改如果你问有关安全,请参阅我的底部编 修改

Edit If you are asking about security, see my addendum at the bottom Edit

PHP有一个序列化提供这一特定目的功能。传递一个数组,它会给你一个字符串重新它presentation。当你想将其转换回一个数组,你只需要使用反序列化功能。

PHP has a serialize function provided for this specific purpose. Pass it an array, and it will give you a string representation of it. When you want to convert it back to an array, you just use the unserialize function.

$data = array('one'=>1, 'two'=>2, 'three'=>33);
$dataString = serialize($data);
//send elsewhere
$data = unserialize($dataString);

这是经常使用的偷懒codeRS将数据保存到数据库中。不推荐使用,但可以作为一个快速/肮脏的解决方案。

This is often used by lazy coders to save data to a database. Not recommended, but works as a quick/dirty solution.

附录

Addendum

我是你正在寻找一种方式来可靠地发送数据,而不是安全的IM pression下。不管你如何传递数据,如果它要通过用户​​系统,你不能相信它。一般来说,你应该在一些地方保存在服务器和放大器上;使用凭据(饼干,会话,密码等)来关注一下吧。

I was under the impression that you were looking for a way to send the data reliably, not "securely". No matter how you pass the data, if it is going through the users system, you cannot trust it at all. Generally, you should store it somewhere on the server & use a credential (cookie, session, password, etc) to look it up.

这篇关于PHP,通过POST传递数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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