【发布时间】:2023-04-07 10:36:01
【问题描述】:
例子:
用户调用:
http://www.example.com/?mysecret=hello&second=world&third=bar
如果“mysecret”正确,则设置 cookie 并将用户重定向到:
http://www.example.com/?second=world&third=bar
代码示例:
if(is_page(MY_LOCKED_PAGE)) {
if($_COOKIE["unlocked"]=="y") {
// proceed
} else if(isset($_GET["mysecret"])) {
setcookie('unlocked','y',time()+3600*24*180,'/',"",false,true);
// strip mysecret from the URL
// redirect to the original URL without the get parameter "mysecret", but keeping other get parameters
} else {
// redirect 404
}
}
填写缺失的代码 - 剥离参数 mysecret 并重定向到相同 url 的最快方法是什么?
【问题讨论】:
-
header("Location: ./?second=world&third=bar");? -
使用
unset($_GET["mysecret"])删除它。 -
Ofc。但让我们假设我不知道其他 get 参数是什么。问题是拆分和重新解析 url 的最快方法。
-
@alpha 也许我想复杂我会试试
标签: php get url-redirection