473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

user can login twice by using different browser

How can i make a code in php that user can not login twice by using 2 different browsers.

I have in my database a colom user_session.

If he logs in in Ie 2 times ,the second time he re-direct to the main page.
In firefox or chrome my code works too.
But if you use 2 browsers you can login twice.

My site is a chatsite.

with 2 user inlog 1 inlog is invisible and one not.
they both can type and go to different rooms.

i dunno why you can not see the second login his name has gone.

please help.
Aug 11 '12 #1
14 8305
ariful alam
185 100+
Every browser has it's own session information and has it's own cookie space. so, whenever you use two browsers to log in those acts like two individual system running.

Now, you can add another column session_status where you can input active/deactive.

whenever a user trying to log in using another browser it will check the stored session is active or deactive. if active, then it show a message and confirms user log in again of new new browser using password and if successful then it rewrite the active session to deactive and store new browser session. And every chat message will check the browser session and the database stored session equals or not before updating the chat message. if not matched then browser will show a message and redirect to log in page.

Hope it's help you. :)
Aug 11 '12 #2
@ariful alam

Ty very much now i can go on with my script.
Have a nice day.

:)
Aug 13 '12 #3
dlite922
1,584 Expert 1GB
By the way, this solution also will prevent multiple logins from different computers. If you are just trying to prevent multiple browsers but enable them to login from multiple computers, then you also need to track IP address or user agent (which is also a good idea to store along with active/deactive status).

what if someone try's to login from the same browser twice? i.e. from a second tab or uses login page in browser history to login again?

Lots to think about when doing user detection like this.

Good luck,

Dan
Aug 13 '12 #4
ariful alam
185 100+
@dlite922,

a login page has a validation area. that first check any user is logged in or not in the current browser using session/cookie. if logged in then the page redirects to the home page/default page that comes after a successful log in.

so, there is no chance to log in second time in same browser in second tab at a same time.
Aug 14 '12 #5
I have this code:

Expand|Select|Wrap|Line Numbers
  1. // check user is logged in 
  2.  
  3.  
  4. session_start();
  5.  
  6. //check if the session exists
  7. if($_SESSION['login'])
  8.  
  9. {
  10.  
  11. //this means they are logged in
  12.  
  13.  
  14.  
  15. header("Refresh:0;URL=http://www.to website with link to chat/");return;
  16.  
  17.  
  18.  
  19.  
  20. }
so if user is logged in he will be send to the webpage.
from the website is a link to the chat.
if you are logged in you will be redirected to website.

still you can login with 2 browsers.

i was busy 4 weaks ,i am a beginner with php.

in mysql i have a column user_status but i dunno how to make the code to set user active.
Aug 16 '12 #6
ariful alam
185 100+
If a user tries to log in your chat site, the site will check the user_status column's value. if the value is deactive than run a update query for the column to change it's value to active for the user. sql update query is like:

Expand|Select|Wrap|Line Numbers
  1. update <table name>
  2. set user_status = 'active'
  3. where userid = '<user login id>'
if the value is active than again a password checking as i described earlier in post#2.

hope works for you. :)
Aug 16 '12 #7
ok ty very much
i go on an try this.
Have a nice day.
Aug 16 '12 #8
Frinavale
9,735 Expert Mod 8TB
It sounds like the server-side solution for monitoring who is logged in is your best solution; however, this introduces a bit of a bug that you need to handle.

Say a user logs in and forgets to log out.

In the database the user is still marked as "logged in" but the person really isn't...they just forgot to log out last time.

Now when the user tries to log in again, they will be blocked from using your application.

This is a bug.

I would ensure that the user has a way to disconnect any other "logged in" instances so to get around the problem.

It is probably best to store the Session ID (since it looks like you're using sessions) in the database. If there is no Session ID for a user, then they aren't logged in anywhere.

If there is a Session ID, you can check if the session id in the database matches the session ID of the request. If it doesn't match, inform the user that they are logged in somewhere else and prevent them from logging in.

If the user wants to log-in even though they are "logged in elsewhere", allow them to log in and store the session ID that they are currently using.

If someone was using the application "elsewhere", then the next request that goes to the server will kick the user out (the user will be redirected to the page saying that they are logged in elsewhere) because the Session IDs don't match for the user.

Be aware that this solution may or may not work in a web farm environment.

-Frinny
Aug 16 '12 #9
ariful alam
185 100+
@Frinavale, what are you saying is already suggested in post#2 http://bytes.com/topic/php/answers/9...er#post3725589
Aug 16 '12 #10
Frinavale
9,735 Expert Mod 8TB
@ariful alam: yup.
I elaborated on it ;)

-Frinny
Aug 16 '12 #11
hello

I made the script that the user can login once.
If he is logged in,you can not go to the login form.
That is working fine.
If you open another browser then i can not hide the form and the user can login for the second time.
The user-status column stays emty so i think there is a bug in the script.
The second login makes the first login invisible user.
Aug 17 '12 #12
hello

i Have now this code but i see nothing in de database in the column user_status.

What do i wrong


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Get database connection
  3. include 'database.php';
  4.  
  5.  
  6. $sql = mysql_query("UPDATE chat_users SET user_status='active' WHERE id='$user_status' ");
  7. $sql_doublecheck = mysql_query("SELECT * FROM chat_users WHERE id='$user_status' AND user_status ='active'");
  8.  
  9.  
  10.  
  11. if($user_status=='active' ){
  12. echo "<strong><font color=red>You are loggged twice in now !!!!</strong>Go to website<br />";
  13.  
  14.  
  15.  
  16. header("Refresh:0;URL=http://www.chatwebsite.****/");return;
  17.  
  18. }
  19.  
  20.  
  21. if($user_status =='inactive'){
  22.     echo "<strong><font color=green>you may login now welcome</font></strong>";
  23.  
  24.  
  25. header("Refresh:0;URL=http:/loginform.php");return;
  26.  
  27. }
  28.  
  29. ?>
Aug 17 '12 #13
ariful alam
185 100+
when a user tries to login first check the user is already active or not.
if not active
update table column user_status='active'
and
redirect him to chat screen/page/application
if (active)
through a message that the user is already active with a password box to give the password again to make this login as active.
if the user give the correct password again for the user id then, deactive the previous login and update this login to active.



moreover, with every chat message, check the session is active in database or not. if not active, then do not update this chat message in database and kick out to the log out page.
Aug 17 '12 #14
Hello everybody

I have fixed it
Thank you very much for you help

Have a nice day.

Thank you !!!!!!!!!!!
Aug 18 '12 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joe | last post by:
I have 3 servers server1: http://server1/login.asp, http://server1/page1.as server2: http://server2/login.asp, http://server2/page1.as server3: http://server3/login.asp, http://server3/page1.as ...
9
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in...
3
by: Joey Lee | last post by:
Hi, Does anyone knows how to control user login that only a single userid can login at a time? Thanks Joey
5
by: simon | last post by:
well i have admin panel and agent panel. when i open admin panel and log in it works fine. but when agent opens agent panel in different pc and login and acts something like open a page or so,...
3
by: Jukka K. Korpela | last post by:
Some time ago in this group, someone suggested that we should develop a "different" user style sheet to demonstrate what a user style sheet or a browser style sheet _could_ do. I guess the idea was...
22
by: klenwell | last post by:
I'm in the process of refactoring the php code base I've amassed over the last few years into an object-oriented framework. I'm about to start in on the authentication/login extension and I've...
4
cobra35y
by: cobra35y | last post by:
Good Afternoon, I am new to the world of programming. after reviewing this site for info pertaining to my situation, i have declared a loss and posting for help. maybe i am just overlooking the...
4
by: sightless | last post by:
Hi all, Is it possible to capture Windows user login in Unix? We have a AIX Unix system that allows users to login (using a common login) and run scripts. At the end of the day, we cannot find out...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.