点击隐藏推荐人

Ale*_*lex 7 html javascript php redirect http

当我点击我网站上的链接时,我想隐藏推荐人.要更好地了解我想要做什么:当有人点击我网站上的链接时,我不希望其他网站所有者知道访问者来自哪里.

我不在乎它是由PHP,HTML还是Javascript完成的.

我试过HTML刷新,javascript window.location,javascript弹出,PHP标题重定向,但没有任何效果.

Mar*_*rcG 12

截至2015年,这是您阻止发送Referer标头的方式:

<meta name="referrer" content="no-referrer" />

只需将其添加到网页的head部分即可.适用于链接和Ajax请求.


hon*_*ovk 9

这是一个傻瓜式的方法.我在一个应用程序中使用此脚本,该应用程序有时会链接到第三方网站,这些网站的网址需要保密.

<?php
session_start();

/**
  Setp 1. Get the query string variable and set it in a session, then remove it from the URL.
*/
if (isset($_GET['to']) && !isset($_SESSION['to'])) {
    $_SESSION['to'] = urldecode($_GET['to']);
    header('Location: http://yoursite.com/path/to/this-script.php');// Must be THIS script
    exit();
}


/**
  Step 2. The page has now been reloaded, replacing the original referer with  what ever this script is called.
  Make sure the session variable is set and the query string has been removed, then redirect to the intended location.
*/
if (!isset($_GET['to']) && isset($_SESSION['to'])) {
    $output = '<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="none">
<title>Referral Mask</title>
</head>
<body>
<h3>Redirecting...</h3>
<script>window.location.href="'.$_SESSION['to'].'"</script>
<a href="'.$_SESSION['to'].'">Here is your link</a>
</body>
</html>' . "\n";
    unset($_SESSION['to']);
    echo $output;
    exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="none">
<title>Referral Mask</title>
</head>
<body>
<h1>Referral Mask</h1>
<p>This resource is used to change the HTTP Referral header of a link clicked from within our secure pages.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

此脚本使用PHP和JavaScript从标头中可靠地删除原始引用者.


H.B*_*.B. 9

在 HTML 5 中,链接应该支持rel="noreferrer"这个目的。


ski*_*ulk 2

更新的代码:

此代码仅作为概念证明。离开父页面的导航将被取消,目标 URL 将被发送到 iframe。iframe 加载一个 dara url,它被视为“空”原始文档。当框架收到消息时,它会将用户重定向到带有“null”引用的目标 URL。由于该帧具有空源,因此无法直接向其发送消息。因此,另一个网页可能会通过自己的匿名 iframe 拦截该消息。在生产中,您仍应在链接上使用 rel="noreferrer",以防您的用户禁用了 javascript,或者您的页面上出现 javascript 错误。在禁用 JS 的旧浏览器的情况下,引荐来源网址仍然可能会被暴露。该示例可能仅在网页正文之后加载,因此在页面完全加载之前的任何点击都可能不会被脚本处理。

改进的工作流程包括生成加密密钥、将其添加到 iframe 内、在发送消息之前对目标 URL 进行加密,然后在 iframe 内对其进行解密。这样您就无需担心第三方窥探。

(function($) {

  var frame = $('<iframe sandbox="allow-scripts allow-top-navigation" src="data:text/html;charset=utf-8,<scr\ipt>window.addEventListener(\'message\', function(event){ if(event.origin == \'' + window.origin + '\') top.window.location = event.data; });</scr\ipt>" style="displayyyy: none !important;">').appendTo('body');

  $('a').click(function(event) {

    frame[0].contentWindow.postMessage( event.target.href, '*' );
    return false;

  });

})(jQuery);
Run Code Online (Sandbox Code Playgroud)

原帖:

这是我尝试使用空白 iframe 的后备解决方案。我还没有让它工作,但我正在分享它,以防其他人想摆弄它。从技术上讲,该框架是跨源的,因此您不能仅单击框架中的链接。我的想法是使用 postMessage 使框架自行点击。

https://jsfiddle.net/skibulk/0oebphet/39/

(function($){

  var frame = $('<iframe src="about:blank" style="displayyyy: none !important;">').appendTo('body');

  $('a[rel~=noreferrer]').click(function(event){

    var win = frame[0].contentWindow;
    win.$ = $;

    frame
    .contents()
    .find('body')
    .append(event.target.outerHTML)
    .append( "<scr\ipt> window.addEventListener('message', function(event){ document.append(event.data); $('a').click(); }); </scr\ipt>" );

    win.postMessage('Hi','*');
    return false;

  });

})(jQuery);
Run Code Online (Sandbox Code Playgroud)