【php】使用重定向,佯装表单处理页面不存在

WBOY
Release: 2016-06-13 12:17:32
Original
918 people have browsed it

【php】使用重定向,伪装表单处理页面不存在

php的重定向,很简单,除去直接打印出重定向的JavaScript代码以外,

使用原生态的php重定向是这样的:

<?phpheader ("location: url");exit;?>
Copy after login

一读到这条语句则会马上跳转到指定的重定向url。

当然,PHP,首先要清楚,header()函数必须放在php程序的开头部分,而且之前不能有另外的header()函数或者 setcookie() 被调用,如果是带有网页输出,本语句必须放在

标记之前,当然,一般我们重定向的时候也无须顾及这一点,因为用到重定向基本上就不读下面的内容了。

使用重定向可以伪装表单处理页面不存在。使得黑客不会这么容易发现我们的表单处理页面。因为表单处理页面一般涉及到数据库操作。不可以让别人输入网址就访问。

比如如下页面redict.php,在实际中是存在的,但你不输入正确的参数a,或者不正确提交表单打开此页,则给你一个404,让你以为这页根本不存在。一般没有人这么容易,猜得出这一页处理的参数是a的。所以起到了保护表单处理页的效果。

这段保护代码非常简单思想仅仅是:判断是否有这个要处理的参数,如果没有这个参数,则重定向到一个本目录内根本就不存的页面:

<?phpif (empty($_REQUEST["a"])){	header("location: error.php");	exit;}else{	//这里仅仅是为了设置正常的编码输出“呵呵”而已!。	header("Content-type: text/html; charset=utf-8"); 	echo "呵呵";}?>
Copy after login



Related labels:
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!