简体   繁体   English

array_values在本地主机中工作,但在服务器上什么也不返回?

[英]array_values works in localhost, but returns nothing on server?

Update: I found the cause. 更新:我找到了原因。 It was because the file only had carriage returns. 这是因为文件仅包含回车符。 After replacing them with CR+LF ( \\r\\n ), it works normally on the server. 用CR + LF( \\r\\n )替换它们之后,它可以在服务器上正常工作。

Original post: 原始帖子:

I just uploaded my site to my webhost and I noticed a strange issue regarding POST data. 我刚刚将网站上传到我的虚拟主机,但发现有关POST数据的奇怪问题。 On localhost, everything works as it should, but on the server for some reason the POST data seems to vanish in the middle of processing? 在localhost上,一切正常运行,但是由于某种原因在服务器上,POST数据似乎在处理过程中消失了?

The site submits data from a form to guestbookFormProcessor.php: 该站点将表单中的数据提交给guestbookFormProcessor.php:

<!doctype html>
<html lang="en">
<head>
    <title>Add Guestbook Comment</title>
    <meta charset="UTF-8" />
</head>
<body>

<?php
    var_dump($_POST); // This returns data OK on the server
    // Process POST data
    $unsafeFormData = array_values($_POST);
    var_dump($unsafeFormData); // This returns nothing on the server!
    // anything after this point will not appear on the page, not even echos
?>

</body>
</html>

But that outputs nothing at all on the server! 但这在服务器上什么也不输出!

If I add an echo 'Test'; 如果添加echo 'Test'; , it appears on the page, but if I add it after the $unsafeFormData = array_values($_POST); ,它会显示在页面上,但是如果我在$unsafeFormData = array_values($_POST); 之后添加它 then it does not appear?! 那么就不会出现?

In fact, anything I add after that row, does not appear on the page. 实际上,我在该行之后添加的任何内容都不会显示在页面上。 I also checked for any strange characters in the row, but it looks normal even to a hex editor. 我还检查了该行中是否有任何奇怪的字符,但是即使对于十六进制编辑器也看起来很正常。 What could be wrong? 有什么事吗 It seems to be related to the array_values() function since this happens: 由于发生这种情况,它似乎与array_values()函数有关:

var_dump($_POST);
array(5) { ["name"]=> string(4) "Juha" ["antispam"]=> string(1) "4" ["antispamIndex"]=> string(1) "1" ["message"]=> string(4) "Test" ["submit"]=> string(4) "Send" } array(5){[“ name”] => string(4)“ Juha” [“ antispam”] => string(1)“ 4” [“ antispamIndex”] => string(1)“ 1” [“ message “] =>字符串(4)”测试“ [”提交“] =>字符串(4)”发送“}

var_dump($unsafeFormData);
(no output at all!) (完全没有输出!)

Why would the POST data disappear after array_values()? 为什么POST数据在array_values()之后消失了?

Thanks! 谢谢!

I found the cause. 我找到了原因。 The php file only had carriage returns, which apparently are not enough on the webhotel I am using. php文件仅包含回车符,这显然在我使用的Webhotel上还不够。 When I replaced all CRs with CR + NL ( \\r\\n ), everything works as it should. 当我用CR + NL( \\r\\n )替换所有CR时,一切正常。

Really strange, that! 真的很奇怪!

i suggest you use echo and foreach 我建议你使用echo和foreach

$arr=(5,10,15,20);

foreach($arr as $value)

{
echo $value;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM