php禁止直接从浏览器输入地址访问.php文件的方法
这篇文章主要介绍了php禁止直接从浏览器输入地址访问.php文件的方法,实例总结了判断来源URL与定义常量两种方法来实现这一功能,是非常具有实用价值的技巧,需要的
本文实例讲述了php禁止直接从浏览器输入地址访问.php文件的方法。分享给大家供大家参考。具体实现方法如下:
一般来说对于有些重要的文件我们并不希望用户可以直接输入地址进行访问,对此我们需要进行一些设置。下面总结了一些php禁止直接从浏览器输入地址访问.PHP文件方法,非常实用。
比如说 这个文件我不想让别人直接从浏览器输入地址访问。
但是如果从任何网站连接过来不可以访问的话,本机建立连接也无法访问跳转到另外的地址。
1.在xx.php文件头部写上以下代码就可以了
复制代码 代码如下:
$fromurl="http://www.jb51.net/"; //跳转往这个地址。
if( $_SERVER['HTTP_REFERER'] == "" )
{
header("Location:".$fromurl); exit;
}
这样只需要简单伪造来源就可以了,对此我们还可以进行如下操作:
2. 在程序中定义一个标识变量
复制代码 代码如下:
define('IN_SYS', TRUE);
3. 在config.php中获取这变量
复制代码 代码如下:
if(!defined('IN_SYS')) {
exit('禁止访问');
}
后面的两种方法是我们在很多cms中碰到的。
希望本文所述对大家的PHP程序设计有所帮助。
,
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The method of customizing resize symbols in CSS is unified with background colors. In daily development, we often encounter situations where we need to customize user interface details, such as adjusting...

Using locally installed font files in web pages Recently, I downloaded a free font from the internet and successfully installed it into my system. Now...

Realize the gap effect of card coupon layout. When designing card coupon layout, you often encounter the need to add gaps on card coupons, especially when the background is gradient...

The problem of container opening due to excessive omission of text under Flex layout and solutions are used...

How to solve the display problem caused by user agent style sheets? When using the Edge browser, a div element in the project cannot be displayed. After checking, I posted...

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

How to obtain dynamic data of 58.com work page while crawling? When crawling a work page of 58.com using crawler tools, you may encounter this...

Implementing responsive layouts using CSS When we want to implement layout changes under different screen sizes in web design, CSS...
