0
我們需要檢查訪問該站點的用戶是否已登錄。如果不是,則必須將其重定向到登錄屏幕。我試圖找到一個JS解決方案,發現here,但控制檯仍在吐出the user is not logged in
即使他們是。Bigcommerce重定向登錄如果註銷
我檢查該cookie的Bigcommerce使用,它似乎仍然使用LoginEmail
//this will allow you to mention the cookie by index
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
//set variable that will check if login email exists
var loggedIn = getCookie('LoginEmail');
//logic that will output different content based on the loggedIn Status
if(typeof loggedIn === 'undefined'){
console.log("They are not logged in!");
window.location.replace("/login.php");
}
else{
console.log("They are logged in! ");
}
我與模板主頁觸發此。提前致謝!
你的意思是,如果有人訪問你的網站訪問者必須登錄查看您的網站? –
@RajKumarBhardwaj很好。我最終通過檢測登錄按鈕div'guest-user'來尋找不同的方法,如果爲true,則重定向到login.php。當用戶登錄時,由於模板中的「if」語句,「guest-user」div會消失。 – scopeak