How can characters inside a comment affect the running of a script?

How can characters inside a comment affect the running of a script? This is a case where a script worked last week but not now. I can only think that a new(er) version of PHP was installed at the web host and that version has a bug. If it’s my fault, I can’t see how. So, is this a PHP bug, a GoDaddy problem, or me?

Below is only a piece of the entire script that I have reduced down to this small failing fragment named ‘a.php’. What should happen is that clicking ‘submit’ simply reloads the file, now called by the post method. For the ones that fail, after the submit button is clicked, IE shows ‘This page can’t be displayed’; FF shows ‘The connection was reset - The connection to the server was reset while the page was loading.’; Chrome shows ‘No data received’; Safari shows an empty screen. No errors appear in the PHP error log file (defined in php.ini). I’ve looked at the file with WinHex and there are no unicode or other strange extras. It appears that the comment characters are being ignored and the rest of the line is being parsed and acted upon somehow. ‘allow_url_fopen’ is true but the statement shouldn’t be part of the running script anyway. This is using PHP v5.3.24 and v5.4.19 on multiple shared Linux hostings on GoDaddy. I tried these examples on a local WAMP installation (with PHP v5.6.0 or v5.4.23) and they all work without problems.

In the full script, I used the last method to get it working again, i.e. move the URL string into a variable and use that variable as the function’s argument.

These four fail:

<?php // commented line at end
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
//file_get_contents('http://abc.com');
?>
<?php // commented line at beginning
//file_get_contents('http://abc.com');
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
?>
<?php // use other commenting characters
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
/*file_get_contents('http://abc.com');*/
?>
<?php // W3C validated with commented line at end
echo '<!DOCTYPE html>';
echo '<head>';
echo '<meta charset="UTF-8">';
echo '<title>title</title>';
echo '</head>';
echo '<body>';
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
echo '</body>';
echo '</html>';
//file_get_contents('http://abc.com');
?>

These four work as expected:

<?php // remove offending line
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
?>
<?php // change function name
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
//zile_get_contents('http://abc.com');
?>
<?php // change from URL to local file
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
//file_get_contents(b.txt);
?>
<?php // set var to URL and use var as argument
echo '<form action="a.php" method="post">';
echo '<input type="submit" name="submit" />';
echo '</form>';
//$u = 'http://abc.com';
//file_get_contents($u);
?>

Thanks for reading this far and for any ideas.

You could try to add a log to a file on each of the lines in your failing scripts… It could give you an idea of the problem.

From what you’re saying, the comment “//” wouldn’t work? That would be weird. It should give you a syntax error with the first line then… XFile song

Did you try to put a space between “//” and “file_get…” ?
Did you try with other functions? Like “// echo ‘1234’” and check in the sources if “1234” is displayed.