|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-10-04 12:39 UTC] craig at logicshock dot co dot uk
Description:
------------
While trying to use a PHP script to read the contents of another .php file using
fopen(), it appears that PHP might be executing/skipping/altering the text as PHP
code instead of treating it as plain text.
The result is nothing like as would be expected as shown below, the result is
missing lots of text. 2 versions of PHP have been tried 5.3.1 and 5.3.3 on Windows
Vista and 7 both x86 and on two versions of Ubuntu server 8.10 & 9.04, the result
is the same across all testbeds.
Tried using fgets, fread and file_get_contents, all display the same result.
This error was reproduced and verified by a colleague.
Test script:
---------------
Calling script (index.php):
ls_execute();
function ls_execute()
{
$fp = fopen('code.php', 'r') or die('Cannot open that source resource');
while(!feof($fp))
$data .= fread($fp,128);
fclose($fp);
return $data;
}
The file to be read (code.php):
<?php
echo " This is a test!";
?>
Expected result:
----------------
<?php
echo " This is a test!";
?>
Actual result:
--------------
"; ?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 22:00:01 2025 UTC |
Ok, the browser result is: <html><body> // This is a test comment, doesnt matter that it is not in the php tags because this // file SHOULD NEVER BE EXECUTED! "; ?> </body></html> It shows that the browser is only getting 'part' of the text as a response. And the complete test code is: <?php echo ls_execute(); function ls_execute() { $fp = fopen('code.php', 'r') or die('Cannot open that source resource'); while(!feof($fp)) { $data .= fread($fp,128); } fclose($fp); return $data; } ?>