Home > Backend Development > PHP Tutorial > Detailed explanation of how to set index.php file as read-only in php

Detailed explanation of how to set index.php file as read-only in php

怪我咯
Release: 2023-03-12 21:46:01
Original
2634 people have browsed it

Since the ftp of my website does not have the ability to directly set the attributes of the files in the space, I wrote a piece of php code to modify the index.php file attributes

to After setting the read-only attribute in the index.php file, the Trojan will not have the permission to append advertisements to the end of your file.
Let’s look at the specific code below and set index.php to be read-only:

The code is as follows:

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

Save the above content as setread.php , thenupload to the space, and directly browse the address with a browser to set read-only.
However, after setting this read-only attribute, you will not have permission through ftp. Delete index.php. If you need to delete or overwrite index.php, please use the following code to set the read and write permissions of index.php.
The following is the code to set index.php to read and write:

The code is as follows:

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

Save the above content as: setwrite.php, you can set the read by accessing it through the browser Write permission is granted.

The above is the detailed content of Detailed explanation of how to set index.php file as read-only in php. For more information, please follow other related articles on the PHP Chinese website!

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