php access prohibition method: 1. Write the "if( $_SERVER['HTTP_REFERER'] == "" ){...}" code in the header of the php file; 2. Define a Identify the variables; 3. Get the variables in config.php.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
How to prohibit access to php?
php method to prohibit directly entering the address from the browser to access the .php file:
The specific implementation method is as follows:
Generally speaking For some important files, we do not want users to directly enter the address to access them, so we need to make some settings for this. The following summarizes some PHP methods to prohibit accessing .PHP files directly from entering the address in the browser, which are very practical.
For example, I don’t want others to access the file https://www.jb51.net/xx.php by entering the address directly from the browser.
But if you cannot access https://www.jb51.net/xx.php from any website, you will not be able to access another address after establishing a connection locally.
1. Just write the following code in the header of the xx.php file
The code is as follows:
$fromurl="https://www.jb51.net/"; //跳转往这个地址。 if( $_SERVER['HTTP_REFERER'] == "" ) { header("Location:".$fromurl); exit; }
This way you only need to simply forge the source. , we can also do the following:
2. Define an identification 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('禁止访问'); }
The following two methods are what we have encountered in many cms.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to prohibit access method in php. For more information, please follow other related articles on the PHP Chinese website!