Reputation: 13
Consider a webpage say, http://www.somedomain.tld/page1.php I don't want someone open page1.php's more than one instances. If the user opens, the same page in multiple browsers he gets disconnected with a warning message.
Any suggestions how to proceed with this? Possible cookie check, simple .htaccess implementation,IP check?
Please let me know if you need further clarifications regarding the scenario.
LINKED: Restrict multiple page access by a user from the same IP
EDIT: accepted "deceze's" direction.
@Mods : You may please close this question.
Upvotes: 1
Views: 977
Reputation: 522461
So, the two tools you have here are IPs and cookies.
IPs are not unique to a user. Forget about them. IPs are a delivery mechanism for routing data, they are way too coarse to identify users.
Cookies are not shared across browsers, so you cannot identify a user using cookies cross-browser.
Additionally, the web is stateless. There isn't one persistent connection between the browser and the server while the web site is open. Once the page is loaded, it stays open in the browser, but there's no communication between it and the server going on.
Given these circumstances, it's virtually impossible to do what you ask for using IPs or cookies. At least without some side effects, which may range from a user logging himself out of his own account or people who share the same IP dead-locking each other.
What you should do is to write your app in a way that's embracing the stateless nature of HTTP requests. You can identify a user by giving him a unique cookie. Conversely, a user without cookie is a new user (including different browsers); use this information to your advantage. If you need a certain process to be finished before something else can be done, you need to keep this state server-side and tie it to a specific user. I.e. "the user with cookie XYZ needs to do action C next", then when the user makes an HTTP request to your server, have the server evaluate the request and decide whether it fits in with whatever the user is supposed to do; respond appropriately by redirecting or denying the request.
Upvotes: 2
Reputation: 3677
Store the IP Address, and check each time with this value and URL requested, with this you can decide which one can see your webpage (how many times too).
Restrict multiple page access by a user from the same IP
Upvotes: 0
Reputation: 2968
if there is a login, then my solution might work for you..
if it is in multiple browser, that means in second browser user has to login again ..
So you make a note in your DB, where user info/login info is stored that once login you wont be able to login again...
Blocking a user from same browser in different Tab might not be possible
Thanks
Upvotes: 1