Php prohibits access to the. php file directly from the address entered in the browser,
This example describes how php prohibits access to the. php file directly from the address entered in the browser. Share it with you for your reference. The specific implementation method is as follows:
In general, we do not want users to directly enter the address to access some important files. We need to make some settings for this. The following summarizes some php methods that prohibit direct access to the. php file from the browser input address, which is very practical.
For example, the http://www.bkjia.com/xx.php file I don't want someone to access directly from the browser input address.
However, if you have accessed http://www.bkjia.com/xx.php from any website, you cannot connect to another address.
1. Write the following code in the header of the xx. php file.
Copy codeThe Code is as follows: $ fromurl = "http://www.bkjia.com/"; // jump to this address.
If ($ _ SERVER ['HTTP _ referer'] = "")
{
Header ("Location:". $ fromurl); exit;
}
In this way, you only need to simply forge the source, and we can also perform the following operations:
2. Define an identifier variable in the program
Copy codeThe Code is as follows: define ('in _ SYS ', TRUE );
3. Get this variable in config. php.
Copy codeThe Code is as follows: if (! Defined ('in _ SYS ')){
Exit ('Access prohibited ');
}
The following two methods are met in many cms.
I hope this article will help you with PHP programming.