How to prevent others from directly accessing php files

Guanhui
Release: 2023-02-28 21:40:02
Original
3594 people have browsed it

How to prevent others from directly accessing php files

How to prevent others from directly accessing php files

You can judge whether a certain constant is defined or whether the defined value is the same. If it is not If the definition or value is different, the script will stop running.

defined('IS_ALLOW') or die('禁止访问!');
Copy after login

Access result: Access prohibited!

If you need to reference it in other php files, you can define the constant first and then reference it.

A.php

defined('IS_ALLOW') or die('禁止');

echo "访问成功!";
Copy after login

B.php

define('IS_ALLOW', true);

require './A.php';
Copy after login

Result of accessing B.php: Access successful!

The above is the detailed content of How to prevent others from directly accessing php files. 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