Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  105] [ 1]  / answers: 1 / hits: 8213  / 10 Years ago, tue, february 11, 2014, 12:00:00

I am using codeigniter session to store user login. When user opens in multiple tab, on logout in one tab , I want the page to be auto refreshed while user visiting the other tab. Is this possible?


More From » php

 Answers
3

Just tested it out, and the easiest way I can see (which seems to work in Chrome at least, but may need further testing) is setting a cookie.



On logout do something like setcookie('loggedout',1). You'll also need to do the opposite on login - unset($_COOKIE['loggedout'])



Then you just need some simple Javascript...



function readCookie(name) {
var nameEQ = escape(name) + =;
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return unescape(c.substring(nameEQ.length, c.length));
}
return null;
}
window.setInterval(function() {
if(readCookie('loggedout')==1) {
window.location.assign('loggedout.html')
//Or whatever else you want!
}
},1000)


That'll check each second to see if the cookie is set. Magic.


[#47855] Monday, February 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;