【发布时间】:2021-01-25 14:32:31
【问题描述】:
首先,我知道这几乎是不可能的,因为如果可能的话,有人可以窃取 cookie。但是因为我仍然怀疑 1% 左右,所以我觉得我需要问问社区,这样我才能完全知道这是否仍然可能或完全不可能。
假设我有mysite.com/promotion,它是shop.org/aff.php?id=123 的永久链接。 Id 123 是我的附属 ID。访问者单击该链接后,访问者将重定向到 shop.com/index.php(主页)。然后 shop.com 将命令访问者浏览器保存我的附属 cookie。 注意:我对 mysite.org 有访问权限,但对 shop.com 没有任何访问权限。
这种行为的问题是我只能推广shop.org的整体,而我不能推广他的具体产品链接。因为当我给访客一个产品链接时,我不会有任何佣金,因为访客永远不会访问我的附属网址。但是当我给他我的附属网址时,他需要找出产品链接的位置。
现在我将给出一些演示代码来说明这一点。
shop.org/index.php
<?php session_start()?>
<h1>shop.com HOME PAGE</h1>
<div>cookie affiliate: <span>EMPTY</span></div><br>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" ></script>
<script type="text/javascript">
$(function(){
<?php if(isset($_SESSION['aff'])):?>
Cookies.set('aff', '<?=$_SESSION['aff']?>');
<?php endif;?>
var aff = Cookies.get('aff');
if(aff!==undefined){
$('span').text(aff);
}
})
</script>
shop.org/aff.php?id=123
<?php session_start();
$_SESSION['aff'] = $_GET['id'];
header('Location:https://shop.org/index.php');
shop.org/product.php
<?php session_start();?>
<p>shop.com PRODUCT PAGE</div>
<div>cookie affiliate: <span>EMPTY</span></div><br>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" ></script>
<script type="text/javascript">
$(function(){
<?php if(isset($_SESSION['aff'])):?>
Cookies.set('aff', '<?=$_SESSION['aff']?>');
<?php endif;?>
var aff = Cookies.get('aff');
if(aff!==undefined){
$('span').text(aff);
}
})
</script>
尝试 1:隐藏 iframe 然后使用 js / html meta 重定向
mysite.org/promotion
<!DOCTYPE html>
<html>
<head>
<title>INI REDIRECT</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="5;URL=https://shop.org/product.php" />
</head>
<body>
<iframe src="https://shop.org/aff.php?id=123" width="0" height="0" tabindex="-1" title="empty" style="display:none;"></iframe>
<div>You will be redirect in 5 seconds</div>
</body>
</html>
访问者将无法获得我的附属 cookie,因为他收到警告:A cookie associated with a cross-site resource at https://shop.org/ was set without the 'SameSite' attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with 'SameSite=None' and 'Secure'.
尝试 2:jQuery 加载
<!DOCTYPE html>
<html>
<head>
<title>INI REDIRECT</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="5;URL=https://shop.org/product.php" />
</head>
<body>
<iframe src="https://shop.org/aff.php?id=123" width="0" height="0" tabindex="-1" title="empty" style="display:none;"></iframe>
<div>You will be redirect in 5 seconds</div>
<div id="msgDiv"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" ></script>
<script>
$(function(){
$('#msgDiv').load('https://shop.org/aff.php?id=123');
});
</script>
</body>
</html>
这也会失败,因为 CORS 政策。请记住,我无权访问 shop.org,因此无法启用此功能。
尝试 3:抓取 cookie,然后将这些 cookie 提供给访问者
我没有在这里给出代码,因为我知道这也会失败。原因是我们不能给浏览器跨域cookie。
我的问题是,这完全不可能还是仍然可能?
注意:如果只有 1 个站点,我只需通过电子邮件发送给他们即可满足我的需求。但是,shop.org 只是最常见的会员系统的一个例子。所以这个问题只集中在服务器上,没有任何改变。是的,不可能,但我只是有点怀疑。
【问题讨论】:
-
您需要 shop.org 支持。无论你选择什么。任何重定向、偷偷摸摸的技巧等都不是最好的方法,即使它们今天有效,明天也可能失败。你在 url 中的 id 对他们来说还不够吗?
-
附属链接不需要cookie,它应该是客户端被重定向到的服务器识别和计算的URL参数。
-
感谢@blackblue,但 shop.org 只是一个例子。
-
@SJacks 我在演示中使用 url,然后使用 cookie 保存数据以备将来使用。据我所知,普通的会员系统就是这样的。
标签: javascript php redirect cookies iframe