您好,我正在编写一个个人资料页面脚本,在这个脚本中,我检查传入的$_GET变量的值,并验证它是一个整数,然后我验证这个值与$_SESSION值,以确认他们只能访问自己的帐户。代码如下所示:
// validate $_GET field
if(isset($_GET['identity']) && filter_var($_GET['identity'], FILTER_VALIDATE_INT, array('min_range' => 1))) {
if(isset($_SESSION['user_identity']) && ((int)$_SESSION['user_identity'] === (int)$_GET['identity'])) { // if session exists and is === $_GET['identity']
// Proceed with code例如,如果我尝试传递'0‘、'2-2’、'abc‘或没有值作为$_GET值,查询就会正确地失败,并将它们重定向到主页。
然后,我尝试修改我的.htaccess文件,将URL映射到'profile/1‘,只是为了整理它。
RewriteRule ^profile$ profile.php
RewriteRule ^profile/([0-9]+)$ profile.php?identity=$1 [NC,L]我现在发现,使用上面那些无效的$_GET参数,页面不再重定向。它只是尝试查找“profile/abc”。
有人知道为什么吗?
发布于 2011-10-15 07:40:54
我使用这个,它对我很有效:
RewriteEngine On
RewriteBase /
RewriteRule ^profile$ profile.php
RewriteRule ^profile/([a-z0-9\-]+)$ profile.php?identity=$1 [NC,L,QSA]你是怎么弄到profile/abc的?如果你试图在规则中传递字母,它不会起作用,因为你只指定了数字([0-9]+)。如果你想传递字母,你需要使用:
RewriteRule ^profile/([a-z0-9\-]+)/?$ profile.php?identity=$1 [NC,L,QSA]https://stackoverflow.com/questions/7769774
复制相似问题