How to prohibit access to .php files in php

藏色散人
Release: 2023-03-01 08:42:02
Original
3363 people have browsed it

How to prohibit access to .php files in php

#How to prohibit access to .php files in php?

The example in this article describes how PHP prohibits accessing .php files by directly entering the address from the browser.

The specific implementation method is as follows:

Generally speaking, for some important files, we do not want users to directly enter the address for access, so we need to make some settings for this.

The following summarizes some PHP methods to prohibit accessing .PHP files by directly entering the address from the browser, which is very practical.

For example, I don’t want others to access the file //www.xxx.net/xx.php by entering the address directly from the browser.

But if you cannot access //www.xxx.net/xx.php from any website, you will not be able to access another address even if you establish a connection locally.

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

The code is as follows:

$fromurl="//www.xxx.net/"; //跳转往这个地址。
if( $_SERVER['HTTP_REFERER'] == "" )
{
header("Location:".$fromurl); exit;
}
Copy after login

This way you only need to simply forge the source. For this We can also perform the following operations:

2. Define an identification variable in the program

The code is as follows:

define('IN_SYS', TRUE);
Copy after login

3. Get this variable in config.php

The code is as follows:

if(!defined('IN_SYS')) {
exit('禁止访问');
}
Copy after login

The following two methods are what we have encountered in many cms.

Recommended: "PHP Tutorial"

The above is the detailed content of How to prohibit access to .php files in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!