If a user is already login then from that username he should be not able to login on another system from any where on the internet. I mean only one session should be created for users on my site.
You could do it two ways, block the user from logging in a second time, or log off the first user if second user logs in. With the first method you would store the users timestamp of their last_action, to keep track of their online status. And not allow the user to login if they are already online. The problem with this method is if the user forgets to logout they will have to wait until their last_action reaches the timeout period (you set) before they could log in again. With the other method, you would store the session_id in the database and when the user logs in you would destroy all the previous session variables and set the new session.
Hi! Try This Code: For Any Mistake Or BUG, I Apologize. $UserName = $_REQUEST["UserName"]; $Password = $_REQUEST["Password"]; $query = "select * from Users Where UserName = '$UserName' and Password = '$Password'"; $result = mysql_query($query, $conn); $Found=mysql_num_rows($result); $Row=mysql_fetch_array($result); if($Found==1) { if($Row["OnlineStatus"] == "Offline") { $_SESSION["UserName"] = $Row["UserName"]; mysql_query("UPDATE Users SET OnlineStatus = 'Online' WHERE UserName = '".$_SESSION["UserName"]."'"); print "Logged In"; } else { print "Already Logged In"; } } else { print "Username Or Password Not Found"; } Query When Logout: mysql_query("UPDATE Users SET OnlineStatus = 'Offline' WHERE UserName = '".$_SESSION["UserName"]."'");
That would only work if everyone logs out, if someone forgets to logout they wont be able to log back in.