Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php session_start();
  2.  
  3. require 'admin/config.php';
  4. require 'functions.php';
  5.  
  6. // comprobar session
  7. if (isset($_SESSION['usuario']))
  8. {
  9. // validar los datos por privilegio
  10. $conexion = conexion($bd_config);
  11. $usuario = iniciarSession('usuarios', $conexion);
  12.  
  13. if ($usuario['tipo'] == 'administrador')
  14. {
  15. header('Location: '.RUTA.'admin.php');
  16. }
  17. elseif ($usuario['tipo'] == 'usuario')
  18. {
  19. header('Location: '.RUTA.'usuario.php');
  20. }
  21. else
  22. {
  23. header('Location: '.RUTA.'login.php');
  24. }
  25. }
  26. else
  27. {
  28. header('Location: '.RUTA.'login.php');
  29. }
  30.  
  31. ?>
  32.  
  33. <?php
  34.  
  35. function conexion($bd_config){
  36. try {
  37. $conexion = new PDO('mysql:host=localhost;dbname='.$bd_config['db_name'],$bd_config['user'],$bd_config['pass']);
  38. return $conexion;
  39. }
  40. catch (PDOException $e)
  41. {
  42. return false;
  43. }
  44. }
  45.  
  46. function limpiarDatos($datos)
  47. {
  48. $datos = htmlspecialchars($datos);
  49. $datos = trim($datos);
  50. $datos = filter_var($datos, FILTER_SANITIZE_STRING);
  51.  
  52. return $datos;
  53. }
  54.  
  55. function iniciarSession($table, $conexion)
  56. {
  57. $statement = $conexion->prepare("SELECT * FROM $table WHERE usuario = :usuario");
  58. $statement->execute([
  59. ':usuario' => $_SESSION['usuario']
  60. ]);
  61. return $statement->fetch(PDO::FETCH_ASSOC);
  62. }
  63.  
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement