Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/01/2013, 10:30
vindt89
 
Fecha de Ingreso: febrero-2012
Mensajes: 49
Antigüedad: 12 años, 2 meses
Puntos: 2
Sistema de login usando PHP OO - No funciona

Gente como va?

Bueno la cosa es asi, estoy intentando hacer un sistema de login y es el primero que hago con objetos. La verdad que estoy muy perdido dado que no hace nada, pero ni siquiera me da error de nada.
Les paso los archivos.

Index.php
Código PHP:
Ver original
  1. include 'lib/class.db.php';
  2. include 'lib/class.user.php';
  3. if(isset($_POST['submit'])){
  4.     if(!empty($_POST['user']) && !empty($_POST['pass'])){
  5.         $u = new User;
  6.         $u->Login($_POST['user'], $_POST['pass']);
  7.         if($u->GetUsrOnline () == 1){
  8.             $_SESSION['user'] = $u->GetUser;
  9.             $_SESSION['level'] = $u->GetLevel;
  10.             header ("location:admin/main.php");
  11.         } else{
  12.         echo "algunos errores 1";
  13.         }
  14.     }else
  15.     {
  16.     echo "Algunos errores 2";
  17.     }
  18. }
  19.  
  20.  
  21.  
  22. ?>
  23. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  27. <title>CMS - gestor de contenidos</title>
  28. <!--Css-->
  29. <link href="css/style.css" rel="stylesheet" type="text/css" />
  30. <!--Js-->
  31.  
  32. </head>
  33.  
  34. <body>
  35.     <div id="main">
  36.         <div id="stage">
  37.             <div id="box_login">
  38.                 <form name="login" method="post" action="" autocomplete="off" class="c_general b_10 s_x15">
  39.                 <span class="minitext f_ubuntu">Bienvenido a <strong>CMS - Vindt 1.0!</strong></span>
  40.                     <fieldset>
  41.                         <input type="text" id="user" name="user" placeholder="Usuario" class="b_7 s_basich f_ubuntu"/>
  42.                         <input type="password" id="pass" name="pass" placeholder="Password" class="b_7 s_basich"/>
  43.                         <button type="submit" class="smallbutton blues f_ubuntu_b">Login</button>
  44.                     </fieldset>
  45.                 <span class="minitext f_ubuntu">Si tiene problemas con el ingreso <a href="help.php">click aqu&iacute;</a>.</span>
  46.                 </form>
  47.             </div>
  48.         </div>
  49.     </div>
  50. </body>
  51.  
  52. </html>

Clase user
Código PHP:
Ver original
  1. class User {
  2.    
  3.     private $user_name;
  4.     private $user_level;
  5.     private $user_active;
  6.     private $user_role;
  7.     private $user_online;
  8.     private $user_error = '';
  9.    
  10.     public function Login ($user, $pass) {
  11.         $e = new Error;
  12.         if($user == "" || $pass == "") {
  13.             $error = "<li>Esta todo mal</li>";         
  14.             self::AddError ($error);
  15.         }else{
  16.             $query = "SELECT user_name, user_pasword, user_active, user_level FROM users_sme WHERE user_name = :user AND user_password = :pass;";
  17.             $stmt=DB::getStatement($sql);
  18.             $stmt->bindParam(':user',$user);
  19.             $stmt->bindParam(':pass',$pass);
  20.             $stmt->execute();  
  21.             $total = $stmt->rowCount();
  22.             $row = $stmt->fetchObject();
  23.                 if($total == 1){
  24.                     if($row->user_active==1){
  25.                         $this->user_name = $row->user_name;
  26.                         $this->user_level = $row->user_role;
  27.                         $this->user_online = 1;
  28.                     }
  29.                     else{
  30.                         $error = "<li>Esta mal otra cosa</li>";
  31.                         $e->AddError($error);
  32.                                             }
  33.                 }else{
  34.                     $error = "<li>Esta mal otra cosa2</li>";
  35.                         $e->AddError($error);
  36.                 }
  37.        
  38.        
  39.         }  
  40.     }
  41.     private function AddError ($error) {
  42.         $this->user_error .= $error;
  43.     }
  44.     public function GetErrors () {
  45.         return $this->user_error;      
  46.     }
  47.     public function GetUsrOnline () {
  48.         return $this->user_online;
  49.     }
  50.     public function GetUser(){
  51.         return $this->user_name;
  52.     }
  53.     public function GetUserLavel(){
  54.         return $this->user_level;
  55.     }
  56.    
  57. }

Clase DB

Código PHP:
Ver original
  1. class DB {
  2.     private static $db;
  3.  
  4.     private static function getConnection(){
  5.         if (empty(self::$db)) {
  6.             self::$db = new PDO('mysql:host=localhost;dbname=sales',
  7.                                 'root',
  8.                                 '');
  9.         }
  10.         return self::$db;
  11.     }
  12.     static function getStatement($query){
  13.         return self::getConnection()->prepare($query);
  14.     }
  15. }

Espero me puedan ayudar o guiar con algun tutorial que tengan a mano para facilitarmelo.
Gracias!
__________________
@vindt89