Jump to content

one login at a time help plz


ccrevcypsys

Recommended Posts

so heres what i have and it doesnt work how i want it to ( i want it so that when someone tries to login and there is already a session i will have it update the information in the db with the new sess data and the new times instead of making 1.3 billion of them over the course of the next 2 weeks lol. so if you can help it would be awsome )

<?php

if($_POST['email']==TRUE){
//Check if already logged in
	$query = "SELECT * FROM `sessions`";
	$result = mysql_query($query)or die(mysql_error()."error 1");
	$row = mysql_fetch_array($result, MYSQL_ASSOC)or die(mysql_error()."error 3");
	if($row == TRUE && $row['customer_id']=="36"){
	echo "Already Logged In Click Here To Destroy All Sessions.";
	}else{
		$querys = "SELECT * FROM customer WHERE email = '".$_POST['email']."' AND password='".$_POST['password']."'";
		$results = mysql_query($querys)or die(mysql_error()."error 1");
		$rows = mysql_fetch_array($results, MYSQL_ASSOC)or die(mysql_error()."error 2");
		$login = $_POST['email'];
		if($rows){
		$sessId = rand(50,1000);
			$insert = mysql_query("INSERT INTO sessions (sessId,customer_id,timeStart,timeLast) VALUES (".$sessId.",".$rows['customer_id'].", ".date('his').",".date('his').")")or die(mysql_error());
			if($insert==TRUE){
			setcookie("sessId", $sessId, time()+3600);
			setcookie("customer_id", $rows['customer_id'], time()+3600);
			header("Location: index.php?p=V");
			}
		}
	}
}
?>

Link to comment
Share on other sites

Hello,

 

My views are little different.

 

1.When user log in try to fetch the session id from your session table.(Note: in your table you might have mapped the userid with session id so it would be easier for you to fetch uerid from username/password nad then mapp it to session_id )

 

2.If($sessionid)

      {

        code to update the db

      }

else

{

      code to insert in db

}

 

hope it helps

regards

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.