我有一个登录系统,成功登录后会重定向上一页。例如,如果用户输入 login.php?redirect= https://www.google.com,它将重定向到https://www.google.com。
我希望它重定向到https://www.example.com/https://www.google.com。
(Example.com 是我的域。)
我怎样才能做到这一点?
我已经尝试过的:
header("Location: /". $_POST["redirect_url"]);
和
header("Location: https://www.example.com/". $_POST["redirect_url"]);
但如果它是/page,它会重定向到https://www.example.com//page,带有双斜杠。
有没有办法实现这一目标?
您可以检测并删除 $_POST 中的前导斜杠。
if (preg_match('~^\/~', $_POST['redirect_url'])) {
$_POST['redirect_url'] = substr($_POST['redirect_url'], 1);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句