php中设置index.php文件为只读的方法

yipeiwu_com6年前PHP代码库

为index.php文件设置只读属性后,木马就没权限给你文件末尾追加广告了。
下面我们看具体的代码,设置index.php只读:

复制代码 代码如下:

<?php
function set_writeable($file_name)
{
if(@chmod($file_name,0555))
{
  echo "修改index.php文件只读属性成功";
}
else
{
  echo "修改index.php文件只读属性失败,空间商不支持此操作!";
}
}
set_writeable("index.php");
?>

把以上内容保存成setread.php,然后上传到空间,直接浏览器浏览该地址即可设置只读。
不过设置这个只读属性以后,你自己通过ftp也没有权限删除index.php,如果需要删除或者覆盖index.php请使用以下代码设置index.php的读写权限。
下面是设置index.php读写的代码:

复制代码 代码如下:

<?php
function set_writeable($file_name)
{
if(@chmod($file_name,0777))
{
  echo "修改index.php文件读写属性成功";
}
else
{
  echo "修改index.php文件读写属性失败,空间商不支持此操作!";
}
}
set_writeable("index.php");
?>

保存以上内容为:setwrite.php,通过浏览器访问即可设置读写权限了。

相关文章

php变量范围介绍

例如: 复制代码 代码如下: <?php $a = 1; include 'b.inc'; ?> 这里变量 $a 将会在包含文件 b.inc 中生效。但是,在用户自定义函数...

[PHP]实用函数5

//把一个数字的二进制表示形式转化成十六进制 string bin2hex(string tring) //除去字符串结尾处的空格 string rtrim...

解析thinkphp基本配置 convention.php

复制代码 代码如下:return  array(     /* 项目设定 */    'APP_DEBUG'&nbs...

PHP简单实现合并2个数字键数组值的方法

本文实例讲述了PHP简单实现合并2个数字键数组值的方法。分享给大家供大家参考,具体如下: 先要了解一个基础知识点:PHP合并数组+与array_merge的区别分析 <?...

PHP执行zip与rar解压缩方法实现代码

Zip:PclZip http://www.phpconcept.net/pclzip/index.en.php Rar:PECL rar http://pecl.php.net/pac...