Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2.  
  3. class conexion {
  4. private $conexion;
  5. private $server = "localhost";
  6. private $usuario = "root";
  7. private $pass = "aassdd";
  8. private $db = "Agropacdb;"
  9.  
  10. private $user;
  11. private $password;
  12.  
  13. public function_construct() {
  14. $this->conexion = new mysqli($this->server, $this->usuario, $this->pass, $this->db);
  15.  
  16. if($this->conexion->connect_errno){
  17.  
  18. die("Fallo al tratar de conectar con MySQL: (". $this->conexion->connect_errno.")");
  19.  
  20. }
  21.  
  22. }
  23.  
  24. public function cerrar() {
  25. $this->conexion->close();
  26. }
  27.  
  28. public function login($usuario, $pass) {
  29.  
  30. $this->user = $usuario;
  31. $this->password = $pass;
  32.  
  33. $query = "SELECT id_u, nombre_u, apellido_u, alt_u, pass_u From Usuarios WHERE alt_u = '".$this->user."' and pass_u = '".$this->password."' ";
  34.  
  35. $consulta = $this->conexion->query($query);
  36.  
  37. if($row = mysqli_fetch_array($consulta)){
  38.  
  39. session_start();
  40.  
  41. $_session['id'] = [$id_u];
  42. $_session['nom'] = [$nombre_u];
  43. $_session['ape'] = [$apellido_u];
  44.  
  45. echo "Has iniciado sesion";
  46.  
  47. echo $_session['id'];
  48. echo $_session['nom'];
  49. echo $_session['ape'];
  50.  
  51. } else {
  52.  
  53. echo "Usuario o contrasena incorrectos";
  54. }
  55. }
  56.  
  57. }
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement