How to set index.php file read-only in php

藏色散人
Release: 2023-03-04 09:36:01
Original
3404 people have browsed it

php method to set file read-only: first create a "setread.php" file and add the content as "function set_writeable($file_name) {...}"; then upload the file to the space; finally Browse the address directly through the browser to set read-only.

How to set index.php file read-only in php

Recommended: "PHP Video Tutorial"

Set the index.php file in php as read-only Method

After setting the read-only attribute for 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 to set index.php to be read-only:

<?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, then upload it to the space, and browse the address directly with the browser to set it. Read only.

However, after setting this read-only attribute, you do not have permission to delete index.php through ftp. 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 read and write:

<?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, and you can set the read and write permissions by accessing it through the browser.

The above is the detailed content of How to set index.php file 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