PHP4由fwrite()创建的文件中包含()的问题

PHP4由fwrite()创建的文件中包含()的问题,php,permissions,include,php4,fwrite,Php,Permissions,Include,Php4,Fwrite,我有一个名为generator.php的文件,它使用fwrite()在服务器(Apache,PHP4)上创建result.php result.php中的一行是phpinclude()语句 因此,在generator.php中: if (!is_file($fname)){ $resultfile = fopen($current_path . "/" . $fname, "w+"); } fwrite($resultfile, '<?php include($_SERVER["D

我有一个名为
generator.php
的文件,它使用
fwrite()
在服务器(Apache,PHP4)上创建
result.php

result.php
中的一行是php
include()
语句

因此,在
generator.php
中:

if (!is_file($fname)){
    $resultfile = fopen($current_path . "/" . $fname, "w+");
}
fwrite($resultfile, '<?php include($_SERVER["DOCUMENT_ROOT"] . "'. '/inc/footer.php"); ?>' . "\n");
fclose($resultfile);
chmod($current_path . "/" . $fname, 0755);  
<h2>Sponsored Links</h2>
<!-- begin sidebar_top ad -->
<?php echo $_SERVER['DOCUMENT_ROOT'] . "/ads/sidebar_top.php" . "<hr />";
  include($_SERVER['DOCUMENT_ROOT'] . "/ads/sidebar_top.php"); ?>
<!-- end sidebar_top ad -->
但是当我在浏览器中访问
result.php
时,
include()
语句不起作用。echo语句是这样的,因此我知道路径是正确的

另一个使用相同代码的
test.php
,我使用FTP上传到同一个文件夹中,效果很好

通过FTP恢复时,两个文件中的代码相同

test.php
:(正常工作、回显和包含。)


知道为什么
include()
test.php
(手动创建)中工作而不是在
result.php
(使用
fwrite()
创建)中工作,而两者都在同一文件夹中吗

我所知道的文件之间的唯一区别是:

  • 所有者可能不同(难道不是由用户
    无人创建的
    result.php
    ?)
  • 权限最初是不同的。FTP文件(工作)是
    0775
    ,而使用fwrite()创建的文件(包括不工作)是
    664
    ,由
    generator.php
    0775
    进行chmoded
  • 工作
    test.php
    文件在Mac上用Smultron编辑并通过FTP上传,而
    result.php
    是由Linux上的
    generator.php
    中的
    fwrite()
    通过浏览器调用创建的
  • fwrite($resultfile,.“\n”);
    

    当PHP4安全模式打开时,由另一个uid编写的
    result.php
    无法访问包含的文件,该文件属于另一个uid

    安全模式限制生效。不允许uid为48的脚本访问 /uid 10010拥有的var/www/vhosts/example.com/httpdocs/ads/sidebar_top.php 在第130行的/var/www/vhosts/example.com/httpdocs/results/result.php中

    我通过打开
    php.ini
    并更改为
    safe\u mode\u gid=On
    ,并将我的include目录添加到
    safe\u mode\u include\u dir
    ,解决了这个问题


    我还必须重新启动Apache以使更改生效。

    这是一个多余的连接,但我认为这与问题无关。文件在执行之前是否已关闭?此外,我们是否可以同时看到生成的两个文件?您是否尝试过用FTP浏览器下载result.php并手动检查它们是否相同?另外,您是否得到了任何结果访问result.php(在页面或日志中)时出错?是,请确保在尝试执行它之前调用fclose($fp)。还可以通过ftp发送输出文件并手动检查内容。是的,result.php文件会在很久以后手动执行(通过浏览器)。通过FTP检查时,内容似乎是相同的。实际上,我从result.php(通过FTP获取)中截取了2行代码,并创建了test.php。此外,如果我将“include”替换为“require”,那么它只会停在那个句子处。
    <?php 
    echo $_SERVER['DOCUMENT_ROOT'] . "/ads/sidebar_top.php" . "<hr />";
    include($_SERVER['DOCUMENT_ROOT'] . "/ads/sidebar_top.php"); 
    ?> 
    
    fwrite($resultfile, '<?php include($_SERVER["DOCUMENT_ROOT"] . "/inc/footer.php"); ?>' . "\n");