![](/img/trans.png)
[英]How to redirect to login page after cookie expires in Angular JS?
[英]How to redirect page twice while get cookie
首先,我知道這幾乎是不可能的,因為如果可能的話,有人可以竊取 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'.
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 只是最常見的聯盟系統的一個例子。 所以這個問題只關注服務器,沒有任何變化。 是的,不可能,但我在這里有點懷疑。
我認為這幾乎是不可能的,因為 CORS-Policy 正是為了阻止這種情況。 只有當其他站點允許使用特定的 HTTP-Header 時,您才能執行類似的操作。
您可以嘗試<img src="https://shop.org/aff.php?id=123" style="height: 0; width: 0;">
,但我認為結果與 iframe 相同.
其他方法:
也許商店頁面提供了這種方法,例如使用 GET-Attribute:
shop.com/aff.php?id=123&url=/product/myproduct/
或者
shop.com/product/myproduct/?aff=123
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.