Php prohibits access to the. php file directly from the address entered in the browser ,. Php prohibits access to the. php file directly from the browser input address. this example describes how php prohibits access to the. php file directly from the browser input address. I would like to share with you how php prohibits you from accessing the. php file directly from entering the address 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.
The 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
The code is as follows:
Define ('in _ SYS ', TRUE );
3. get this variable in config. php.
The 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.
Example: php prohibits access to the. php file directly from the address entered in the browser. I will share it with you for your reference...