Thread: php login
View Single Post
Old 05-05-2008, 17:26   #7 (permalink)
jesusfreak101
ie must die
 
jesusfreak101's Avatar
 
Join Date: Jun 2007
Location: Washington
Posts: 921
Send a message via AIM to jesusfreak101
so how would i call the sessions in every page i want authenticated?

or should i create a file and place the sessions in there???

EDIT: I put the following in "checkLogin.php"

PHP Code:
<?

/**
 */
function confirmUser($username$password){
   global 
$conn;
   
/* Add slashes if necessary (for query) */
   
if(!get_magic_quotes_gpc()) {
    
$username addslashes($username);
   }

   
/* Verify that user is in database */
   
$q "select password from users where username = '$username'";
   
$result mysql_query($q,$conn);
   if(!
$result || (mysql_numrows($result) < 1)){
      return 
1//Indicates username failure
   
}

   
/* Retrieve password from result, strip slashes */
   
$dbarray mysql_fetch_array($result);
   
$dbarray['password']  = stripslashes($dbarray['password']);
   
$password stripslashes($password);

   
/* Validate that password is correct */
   
if($password == $dbarray['password']){
      return 
0//Success! Username and password confirmed
   
}
   else{
      return 
2//Indicates password failure
   
}
}

function 
checkLogin(){
   
/* Check if user has been remembered */
   
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
      
$_SESSION['username'] = $_COOKIE['cookname'];
      
$_SESSION['password'] = $_COOKIE['cookpass'];
   }

   
/* Username and password have been set */
   
if(isset($_SESSION['username']) && isset($_SESSION['password'])){
      
/* Confirm that username and password are valid */
      
if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0){
         
/* Variables are incorrect, user not logged in */
         
unset($_SESSION['username']);
         unset(
$_SESSION['password']);
         return 
false;
      }
      return 
true;
   }
   
/* User not logged in */
   
else{
      return 
false;
   }
}
?>

something tells me this isnt right

Last edited by jesusfreak101 : 05-05-2008 at 17:52.
  Reply With Quote