Jump to content

Recommended Posts

I am using a script I got from http://phpsense.com/php/php-login-script.html in order to allow people to login but prevent multiple logins with the same username.  Everything appears to work fine however multiple people can still login simultaneously.  I have verified sessions are being stored with the correct info and it appears cookies are generated as well so why can people login with the same username from different machines simultaneously?  I have included all of the php pages i'm using as well as a copy of my php.ini file.  Any help would be GREATLY appreciated.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/177568-login-script-issues/
Share on other sites

That is a simplistic login in script. It does not have any advanced features to manage things like preventing multiple logins. That would require storing the logged in/out status and information about where the current login came from/session id in a database table.

Link to comment
https://forums.phpfreaks.com/topic/177568-login-script-issues/#findComment-936257
Share on other sites

Now that I have read more carefully I see you are correct.  So I imagine I would need to store some session info in my db and have the pages check whether or not session info is there....if it is not then login is allowed and if it is either login will be rejected or it will be accepted and the other user will be kicked.  So I have the theory....anyone that can help with actual implementation?

Link to comment
https://forums.phpfreaks.com/topic/177568-login-script-issues/#findComment-936280
Share on other sites

Hmm....I have almost no idea how to do that haha.  Creating the database should be simple enough but I'm lost on how to code something along those lines.  Found the code below which looks like it should do what I want so I'm playing with it.

 

#Prevent Membership Fraud

//check if someone is logged in

if (isset($_SESSION['user_id'])) {

//connect to your db

require('../../../connect.php');

/*build query using hirer_id and current_session_id, get count. If query comes back with a 1, it means there is a match. A match is good because it means no one else logged in during their session. On the other hand, a 0 indicates that no match, meaning someone else logged in simultaneously. Zeros get the boot of death.*/

$result = mysql_query('SELECT COUNT(*) FROM user WHERE user_id='.$_SESSION['user_id']." AND session_id='".mysql_real_escape_string(md5(session_id()))."'");

$login_status = mysql_result($result,0,0);

//recall 1 is good, 0 is bad

if (0 == $login_status) {

//give them the boot

//this is copied from my logout script

$_SESSION = array(); //destroy the variables

session_destroy(); //destroy the session itself

setcookie(session_name(), '', time()-300, '/', '', 0); //destroy the cookie

echo 'Hey, someone else logged in using your account info which means you get the boot.';

exit();

}

}

 

Will let you know if this works and if anyone else has an idea or some code that would be fantastic =0)

Link to comment
https://forums.phpfreaks.com/topic/177568-login-script-issues/#findComment-936309
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.