Login   Register  
PHP Classes
elePHPant
Icontem

File: verify_login.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Igor Feghali  >  Power 2 Protect  >  verify_login.php  
File: verify_login.php
Role: Application script
Content type: text/plain
Description: Validates information submitted from login form
Class: Power 2 Protect
Restrict user access to pages based on permissions
 

Contents

Class file image Download
<?

/* #INFO############################################
Author: Igor Feghali
(c) 2003-2006, ifeghali@interveritas.net
----------------------------------------------------
This file is part of Power 2 Protect Class
----------------------------------------------------
################################################# */

/* #DESCRIPTION#####################################
Verifies if LOGIN and PWD typed in the login form
are correct. If yes, jumps to user's initial page
(configured in table $usertable).
################################################# */

// #INCLUDES########################################
include("config.inc.php");
// #################################################

// #CLASS DEFINITION################################
class user
{
    function 
get($con,$usertable,$usercode)
    {
        
$sql "select * from $usertable where usercode = $usercode";
        
$result mysql_query($sql,$con) or die (mysql_error());
        
$row mysql_fetch_array($result);
        
$this->usercode $row["usercode"];
        
$this->usertype $row["usertype"];
        
$this->login $row["login"];
        
$this->pwd $row["pwd"];
        
$this->page $row["page"];
    }
    function 
verifylogin($con,$usertable,$login,$pwd)
    {
        
$sql "select * from $usertable where login = '$login' and pwd = '$pwd'";
        
$result mysql_query($sql,$con) or die (mysql_error());
        if (
mysql_num_rows($result) > 0)
        {
            
$row mysql_fetch_array($result);
            
$this->get($con,$usertable,$row["usercode"]);
            return 
TRUE;
        }
        else
            return 
FALSE;
    }
}
// #################################################

// #GET POST DATA###################################
$login trim($_POST["login"]);
$pwd trim($_POST["pwd"]);
// #################################################

// #INSTANTIATES CLASS##############################
$user = new user;
// #################################################

// #CODE############################################
if ($user->verifylogin($con,$table_user,$login,$pwd))
{
    
$_SESSION["usercode"] = $user->usercode;
    
$_SESSION["usertype"] = $user->usertype;
    
header("location: ".$user->page);
}
else
{
    
header("location: ".$location_loginerror);
}
// #################################################

?>