Home > Backend Development > PHP Tutorial > php在文件指定行中写入代码的方法_PHP

php在文件指定行中写入代码的方法_PHP

WBOY
Release: 2016-06-01 12:11:28
Original
1015 people have browsed it
复制代码 代码如下:
$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后扔在哪就可以。
复制代码 代码如下:








解决方法:这些代码都会在php中写入代码,我们可以写个规则禁止修改php文件.即可,一般服务器中才可以了,如果是虚拟主机的朋友就需要下载代码,经常查后门来解决了
Related labels:
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