Bug generated when the PHP include_once file changes the user to which it belongs

<?php
//test.php
@unlink("/tmp/abc.php");
var_dump(@include_once("/tmp/abc.php"));
swritefile("/tmp/abc.php","<?php echo 123;");
var_dump(file_exists("/tmp/abc.php"));
var_dump(include_once("/tmp/abc.php"));

function swritefile($filename, $writetext, $openmod="w")
{
    if (@$fp = fopen($filename, $openmod)) {

        flock($fp, 2);

        fwrite($fp, $writetext);

        fclose($fp);

        return true;

    }
}

run it three times for the above code:

  • access the test.php, output as follows
bool(false) bool(true) 123int(1)
  • change the user to which the generated file belongs chown vaxili:vaxili / tmp/abc.php . Then visit the test.php output as follows
123int(1) bool(true) bool(true)
  • Delete the generated file rm / tmp/abc.php , and access the test.php, output as follows:
bool(false) bool(true) bool(true)
< H2 > notice that on the third visit, there is no 123 output, but True is returned to check the existence of the file < / H2 >. < H1 > what is the reason for this? < / H1 >
Php
Mar.01,2021

similar to this question

finally decided not to use include_once and replace it with include

Menu