Home >Backend Development >PHP Tutorial >How to prevent php from directly entering the address from the browser to access .php files, _PHP Tutorial

How to prevent php from directly entering the address from the browser to access .php files, _PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:15:061150browse

php prohibits accessing .php files by directly entering the address from the browser,

The example in this article describes how PHP prohibits accessing .php files by directly entering the address from the browser. Share it with everyone for your reference. The specific implementation method is as follows:

Generally speaking, we do not want users to directly enter the address to access some important files, 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 http://www.bkjia.com/xx.php by entering the address directly from the browser.

But if you cannot access http://www.bkjia.com/xx.php from any website, you will not be able to access it even if you establish a connection locally and jump to another address.

1. Just write the following code in the header of the xx.php file

Copy code 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, we only need to simply forge the source. For this, we can also do the following:
2. Define an identification variable in the program

Copy code The code is as follows:
define('IN_SYS', TRUE);

3. Get this variable in config.php

Copy code The code is as follows:
if(!defined('IN_SYS')) {
exit('Access prohibited');
}

The latter two methods are what we encounter in many cms.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/906119.htmlTechArticlephp prohibits accessing .php files directly from entering the address in the browser. The example of this article describes how to prohibit php from directly entering the address from the browser. How to access the .php file by inputting the address. Share it with everyone for your reference...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn