我正在尝试进行退出页面重定向,主要目的是隐藏确切页面路径的http referer数据,
我将此代码用作exit.php页面:
PDO prepared statements:
然后在页面上我添加如下链接:
<?php
/*
* Sets the HTTP headers to redirect the user to a different page
* along with settings the HTTP status code to 307 Temporary Redirect
*/
function redirect($url) {
header("Location: {$url}", true, 307);
}
/*
* Checks if the URL is valid and uses the HTTP or HTTPS scheme.
*/
function valid_url($url) {
if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED|FILTER_FLAG_HOST_REQUIRED) === false) {
return false;
}
$scheme = parse_url($url, PHP_URL_SCHEME);
if($scheme !== "http" && $scheme !== "https") {
return false;
}
return true;
}
if(!isset($_GET['url'])) {
// Missing required argument. What should we do?
redirect("/");
exit;
}else{
$url = $_GET['url'];
if(valid_url($url)) {
redirect($url);
exit;
}else{
// Invalid URL. What should we do?
redirect("/");
exit;
}
}
但是当我使用https://www.whatismyreferer.com/进行测试时 我仍然得到确切的路径,所以我不确定我在这里做错了什么
答案 0 :(得分:2)
正如我在评论中所说,你不能从服务器端隐藏推荐人(据我所知),但有办法这样做。
您可以通过添加如下元元素来告诉浏览器不发送引荐来源:
<meta name="referrer" content="no-referrer">
您可以将referrerpolicy
属性添加到锚元素(区域,img,iframe和链接),它接受以下值:
no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, unsafe-url
更多详情here。
您也可以将noreferrer
传递给rel
属性,更多详情here
此HTTP标头允许您设置有关发送引荐来源的策略,文档here,您可以在PHP中使用header()
函数,如下所示:
header("Referrer-Policy: no-referrer");
或者在你的情况下:
function redirect($url) {
header("Referrer-Policy: no-referrer");
header("Location: {$url}", true, 307);
}
此article详细说明了此功能。