Monday 3 September 2018

array_values ​​works in localhost, but does not return anything on the 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.

Original post:
I just uploaded my site to my webhost and I noticed a strange issue regarding POST data. 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?
The site submits data from a form to 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';, it appears on the page, but if I add it after the $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:
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" }
var_dump($unsafeFormData);
(no output at all!)
Why would the POST data disappear after 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. When I replaced all CRs with CR + NL (\r\n), everything works as it should.

0 comments:

Post a Comment