Set the index. php file to read-only in php

Source: Internet
Author: User
Because the ftp of your website does not directly set the attributes of files in the space, you wrote a php code to modify the index. the PHP file attribute is index. after setting the read-only attribute for the PHP file, the Trojan has no permission to append an advertisement to the end of the file.
The code below shows how to set index. php to read-only:

The code is as follows:
Function set_writeable ($ file_name)
{
If (@ chmod ($ file_name, 0555 ))
{
Echo "the read-only attribute of the index. php file has been modified ";
}
Else
{
Echo "an error occurred while modifying the read-only attribute of the index. php file. the space provider does not support this operation! ";
}
}
Set_writeable ("index. php ");
?>

Save the preceding content as setread. php and then upload it to the space. you can directly view the address in the browser to set read-only.
However, after setting this read-only attribute, you do not have the permission to delete index. php through ftp. if you need to delete or overwrite index. php, use the following code to set the read and write permissions for index. php.
The following code sets index. php to read and write data:
The code is as follows:
Function set_writeable ($ file_name)
{
If (@ chmod ($ file_name, 0777 ))
{
Echo "the index. php file read/write attribute is successfully modified ";
}
Else
{
Echo "an error occurred while modifying the index. php file read/write attribute. the space provider does not support this operation! ";
}
}
Set_writeable ("index. php ");
?>

Save the preceding content as setwrite. php. you can set the read and write permissions by accessing the browser.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.