Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <?php
  2.  
  3. class conexion{
  4.  
  5. private $conexion;
  6. private $host = "localhost";
  7. private $usu = "root";
  8. private $pass = "";
  9. private $db = "gimnasio";
  10.  
  11. public function __construct(){
  12.  
  13. $this->conexion = new mysqli($this->host, $this->usu, $this->pass,
  14. $this->db);
  15.  
  16. if($this->conexion->connect_errno){
  17. die("error no se conecto con mysql:(".$this->conexion-
  18. >connect_errno.")");
  19. }
  20. }
  21.  
  22. public function cerrar(){
  23. $this->conexion->close();
  24. }
  25.  
  26. public function login($login, $pass){
  27. try {
  28. $login=htmlentities(addslashes($_POST["login"]));
  29. $password=htmlentities(addslashes($_POST["password"]));
  30.  
  31. $base=new PDO("mysql:host=localhost; dbname=gimnasio" , "root", "");
  32. $base->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  33.  
  34. $sql="SELECT * FROM personas WHERE idPersonas= :login";
  35.  
  36. $resultado=$base->prepare($sql);
  37. $resultado->execute(array(":login"=>$login));
  38.  
  39. while($registro=$resultado->fetch(PDO::FETCH_ASSOC)){
  40. #echo "Usuario: " . $registro['idPersonas'] . " Contraseña: " .$registro['Nombres'] . "<br>";#
  41. if($_SESSION['roles_idRoles'] == 1){
  42. header("Location:../vista/interfaz_admi_nueva.php");
  43. } else {
  44. header('Location:/index/Usuario/index.php');
  45. }
  46. }
  47.  
  48. $resultado->closeCursor();
  49.  
  50. /*
  51. $this->user = $usuario;
  52. $this->password = $upass;
  53.  
  54. $query = "SELECT idPersonas, Contrasena, roles_idRoles FROM personas WHERE idPersonas ='".$this->user."' AND Contrasena = '".$this->password."'";
  55.  
  56. $consulta = $this->conexion->query($query);
  57.  
  58. if($row = mysqli_fetch_array($consulta)){
  59.  
  60. session_start();
  61.  
  62. $_SESSION['idPersonas'] = $row['idPersonas'];
  63. $_SESSION['Contrasena'] = $row['Contrasena'];
  64. $_SESSION['roles_idRoles'] = $row['roles_idRoles'];
  65.  
  66. if($_SESSION['roles_idRoles'] == 1){
  67. header("Location:../vista/interfaz_admi_nueva.php");
  68. } else {
  69. header('Location:/index/Usuario/index.php');
  70. }
  71. } else {
  72. echo "usuario o password incorrectos";
  73. }
  74. */
  75. } catch(Exception $e) {
  76. die("Error: " . $e->getMessage());
  77. }
  78. }
  79. }
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement