how to check the user login???

A

Anonymous

Guest
ello guys...i have problem to check if the user already login to the system or not. if the user already login, she/he cannot login for the second time at the same time...anyybody knows how to check it???? :help: ...below i have attached my codes to verify user before login. where actually i can add the codes to check the login only allowed once at one time????

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Code:
<?php

   if (!session_start()){
      session_start();
   }

   
   include ("db_connect.php");
   
   $rc  = 0;
   $msg = ""; 

   if (isset($_POST["mybutton"])){
      $username = trim($_POST["name"]);
      $password = trim($_POST["pass"]);
      
      if ($username !=""){
         $SQL = "SELECT * FROM login_dc WHERE (username = '$username') AND (password = '$password')";
         $rs  = mysql_query($SQL);
         if ($row = mysql_fetch_array($rs,MYSQL_ASSOC)){
	    
            $_SESSION["un"] = $row["username"];
            $_SESSION["pw"] = $row["access"];
         }
         else
            $rc = 2;
      }
      else
         $rc = 1;
   
   }

   if (isset($rs)) mysql_free_result($rs);

   if ($rc == 0){
      header ("location: save.php");
      exit;
   }
   else{
      if ($rc == 1) $msg = " ** Please Specify Username ...";
      if ($rc == 2) $msg = " ** Invalid Username or Password ...";

      header("location: login.php?msg=$msg");
	  
   }

?>
 
try using the session_is_registered() function..

example
Code:
<?php

if (session_is_registered($username)) 
{
    echo " you are already registered";
}  else {
    echo "you are not regisitered";
}

?>
 
Better yet Karnetics...
Code:
<?php

if(isset($_SESSION['whatever'])) {
   // ...
}

?>
Anyways... that's the idea ;)
 
sorry guys..i cant understand it well...what actually the purpose of having the session_is_registered() function??? i have tried it out..but it still accept if the user login to the system more than 1 time using the same username and password.
 
Hi,

When you login for the first time, you have to store a session variable, like $_SESSION["un"]. When you logout, you unset this variable (with unset()). Then, by checking the variable with isset($_SESSION["un"]) you will know whether the user has logged in already or not.

Regards.
 
Back
Top