PHP卷曲和序列化问题 [英] Php curl and serialize problem

查看:76
本文介绍了PHP卷曲和序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了通过我的curl脚本传递数组变量,我使用了 serialize ,因为curl POST元素一定不能是数组。

In order to pass array variables via my curl script, I am using serialize because curl POST elements must not be arrays.

序列化后得到的字符串是:

The string that I get after serialization is:

a:10:{s:8:"question";s:18:"How are you doing?";s:11:"view_option";s:6:"select";s:10:"txt_answer";a:4:{i:0;s:8:"dsadsdsa";i:1;s:5:"dsads";i:2;s:10:"dsadsdsdsa";i:3;s:0:"";}s:4:"next";s:1:"9";s:7:"bgimage";s:0:"";s:9:"bck_color";s:0:"";s:12:"border_color";s:0:"";s:11:"select_font";s:1:"1";s:9:"font_size";s:4:"12px";s:4:"poll";s:9:"Get Poll!";} 

Curl做到了:

a:10:{s:8:\"question\";s:18:\"How are you doing?\";s:11:\"view_option\";s:6:\"select\";s:10:\"txt_answer\";a:4:{i:0;s:8:\"dsadsdsa\";i:1;s:5:\"dsads\";i:2;s:10:\"dsadsdsdsa\";i:3;s:0:\"\";}s:4:\"next\";s:1:\"9\";s:7:\"bgimage\";s:0:\"\";s:9:\"bck_color\";s:0:\"\";s:12:\"border_color\";s:0:\"\";s:11:\"select_font\";s:1:\"1\";s:9:\"font_size\";s:4:\"12px\";s:4:\"poll\";s:9:\"Get Poll!\";}

在发送到服务器之前。以上是我在服务器端看到的内容。现在,由于反斜杠,上面的不是不能序列化。

before sending to the server. Above is what I see at the server end. Now, because of the backslashes, above is not unserializable.

我现在该怎么办?如果我只对所有引号进行转义-如何区分CURL进行的转义和可能是数据的转义?

What do I do now? If I just unescape all quotes - how do I distinguish between escapes put by CURL and escapes that could be part of the data?

尝试反序列化转义字符串时遇到的错误是:

The error I get when trying to unserialize the escaped string is:

注意:unserialize()[function.unserialize]:在第8行的/var/www/localserver/test/ser.php中,偏移304为351个字节时发生错误

谢谢

JP

推荐答案

您的服务器可能已启用魔术引号,这意味着您的输入数据已被转义。

Your server probably has magic quotes enabled, which means that your input data is escaped.

您的选项是在 php.ini 文件中禁用它或调用 条带斜线 接收到数据后。

Your options are to disable it in your php.ini file or to call stripslashes on the data when it is received.

作为数据一部分的转义符将被两次转义,因此对它们进行转义不成问题。

Escapes that are part of the data will be double escaped, so unescaping them shouldn't be a problem.

在php.ini中禁用

magic_quotes_gpc = Off

带斜线

stripslashes

$data = stripslashes($_POST['data']);

这篇关于PHP卷曲和序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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