Jump to content

Prevent double login with the same username


nazmy

Recommended Posts

only issue there thorpe is that it handles on a single computer

 

For preventing multi computer logins, make a mysql table that stores

 

SESSIONID  UserID  TimeStamp

 

Every time they move pages if that UsreID is already assigned to another SessionID (no their own) log them out of their current login.

Then delete all Data in this table over X minuites old so you don't have to worry about users who forget to logout.

 

Also delete relative session data on a logout in this table.

 

Its basicalyl a How many users online script altered.

Link to comment
Share on other sites

<?php 
session_start();
include('db.php');
if(isset($_POST['submit'])) :
   $username = strip_tags($_POST['username']);
   $password = sha1(strip_tags($_POST['password']));
   
   $query = sprintf("SELECT ID FROM members WHERE username = '%s' AND user_password = '%s' LIMIT 1;", mysql_real_escape_string($username), mysql_real_escape_string($password));
   $result = mysql_query($query);
   if(1 != mysql_num_rows($result)) :
      
       header('Location: index.php?msg=login_failed');
   else :
       
       $row = mysql_fetch_assoc($result);
       
       $_SESSION['member_ID'] = $row['ID'];
       if (!isset($_SESSION['member_ID'])) {
    		// do login.
    		header('Location: members-only.php');
  		 }
  		 else 
  		 	echo "already logged in";
   endif;
endif;
?>

 

It works!!! I have not tried from multiple pc.... anyway, thanks for the help

Link to comment
Share on other sites

<?php 
session_start();
include('db.php');
if(isset($_POST['submit'])) :
   $username = strip_tags($_POST['username']);
   $password = sha1(strip_tags($_POST['password']));
   
   $query = sprintf("SELECT ID FROM members WHERE username = '%s' AND user_password = '%s' LIMIT 1;", mysql_real_escape_string($username), mysql_real_escape_string($password));
   $result = mysql_query($query);
   if(1 != mysql_num_rows($result)) :
      
       header('Location: index.php?msg=login_failed');
   else :
       
       $row = mysql_fetch_assoc($result);
       
       $_SESSION['member_ID'] = $row['ID'];
       if (!isset($_SESSION['member_ID'])) {
    		// do login.
    		header('Location: members-only.php');
  		 }
  		 else 
  		 	echo "already logged in";
   endif;
endif;
?>

 

Link to comment
Share on other sites


<?php 
session_start();
include('db.php');
if(isset($_POST['submit'])) :
  
   $username = strip_tags($_POST['username']);
   $password = sha1(strip_tags($_POST['password']));
   
   $query = sprintf("SELECT ID FROM members WHERE username = '%s' AND user_password = '%s' LIMIT 1;", mysql_real_escape_string($username), mysql_real_escape_string($password));
   $result = mysql_query($query);
   if(1 != mysql_num_rows($result)) :
       
       header('Location: index.php?msg=login_failed');
   else :
       
       $row = mysql_fetch_assoc($result);
       
         if (!isset($_SESSION['member_ID'])) {
			    
			    $_SESSION['member_ID'] = $row['ID'];
			    header('Location: members-only.php');
			  } else {
			   
			    echo "already logged in";
			  }
       
   endif;
endif;


?>

 

I've made mistake with the last one  ;D.... it does not work... So this this is a new one... It looks ok to me... Can somebody figure it out...

 

 

Link to comment
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.