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

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

问题描述

通过POST发送数组最安全的方式是什么?

Which is the most secure way to send an array through POST?

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

还是使用 implode() 创建单个变量,传递变量,然后使用 explode() 将值取回新数组?

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

推荐答案

编辑 如果您询问安全性,请参阅底部的我的附录编辑

PHP 有一个 serialize 函数用于此特定目的.给它传递一个数组,它会给你一个字符串表示.当您想将其转换回数组时,只需使用 unserialize 函数.

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);

这经常被懒惰的程序员用来将数据保存到数据库中.不推荐,但可以作为快速/肮脏的解决方案.

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

附录

我的印象是您正在寻找一种可靠而不是安全"发送数据的方法.无论你如何传递数据,如果它通过用户系统,你根本无法信任它.通常,您应该将其存储在服务器上的某个位置使用凭据(cookie、会话、密码等)进行查找.

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天全站免登陆