0

Let's say the user is in the page --> mysite.com/product.php?id=5 and he manually removed the ?id=5 and r=the url became this way--> mysite.com/product.php

How can I redirect him to the homepage?

4

2 回答 2

2

Just check to see if the id is missing from the query string. If so, do the redirect.

if (!isset($_GET['id']) || empty($_GET['id'])) {
    //redirect
}
于 2013-02-01T23:25:07.950 回答
0

如果在设置了参数的情况下仍希望页面可访问,请使用此方法:

if(!isset($_GET)){
    header("Location: http://mysite.com/");
    exit;
}

检查是否没有变量被传递到页面,然后进行相应的重定向。
exit在 Header 之后确保没有任何文本发送到浏览器会破坏标题。

如果这将成为死页,请使用 403:

header ('HTTP/1.1 301 Moved Permanently');
header ("Location: http://mysite.com/");
于 2013-02-01T23:27:34.957 回答