Home > Article > Backend Development > Detailed explanation of how to set index.php file as read-only in php
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"); ?>
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"); ?>
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!