Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent a session

Tags:

php

session

When navigating to the Facebook social network, I see that I can open 2 accounts (1 in Firefox and the other in Internet Explorer), or maybe multiple accounts. This is not so good knowing that the Facebook policy allows only to open a session at the same time.

When starting a session, how to prevent the same session (considering the session name $_SESSION['user']) from being re-opened in another browser (Internet Explorer/Safari/Opera...)?

Otherwise, how can I know (with PHP) that a certain session is open in all browsers to prevent the session to be open twice?

like image 994
SmootQ Avatar asked Dec 13 '10 16:12

SmootQ


2 Answers

$token = hash('sha256', rand() . microtime() . $_SERVER['REMOTE_ADDR']) // rand as possible
$_SERVER['user'] = $token;
like image 129
Pradeep Singh Avatar answered Oct 11 '22 08:10

Pradeep Singh


Instead of preventing a new session from being opened in a new browser if there is already an open session elsewhere, consider invalidating any existing sessions to that user account when a new Sign In occurs. This will minimise user frustration, and is simple to implement.

like image 40
karim79 Avatar answered Oct 11 '22 09:10

karim79