Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start();
- require 'admin/config.php';
- require 'functions.php';
- // comprobar session
- if (isset($_SESSION['usuario']))
- {
- // validar los datos por privilegio
- $conexion = conexion($bd_config);
- $usuario = iniciarSession('usuarios', $conexion);
- if ($usuario['tipo'] == 'administrador')
- {
- header('Location: '.RUTA.'admin.php');
- }
- elseif ($usuario['tipo'] == 'usuario')
- {
- header('Location: '.RUTA.'usuario.php');
- }
- else
- {
- header('Location: '.RUTA.'login.php');
- }
- }
- else
- {
- header('Location: '.RUTA.'login.php');
- }
- ?>
- <?php
- function conexion($bd_config){
- try {
- $conexion = new PDO('mysql:host=localhost;dbname='.$bd_config['db_name'],$bd_config['user'],$bd_config['pass']);
- return $conexion;
- }
- catch (PDOException $e)
- {
- return false;
- }
- }
- function limpiarDatos($datos)
- {
- $datos = htmlspecialchars($datos);
- $datos = trim($datos);
- $datos = filter_var($datos, FILTER_SANITIZE_STRING);
- return $datos;
- }
- function iniciarSession($table, $conexion)
- {
- $statement = $conexion->prepare("SELECT * FROM $table WHERE usuario = :usuario");
- $statement->execute([
- ':usuario' => $_SESSION['usuario']
- ]);
- return $statement->fetch(PDO::FETCH_ASSOC);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement