<?php error_reporting(E_ALL); ini_set('display_errors', '1'); require_once "../include/db.php"; # Permite la comunicación con la bd # Se hace la conexión a la BD # $db = new phpDB(); # La variable $db guarda la referencia a la BD $db->connect(); # Se hacen distintas cosas dependiendo del valor del parámetro "action" # if (isset($_POST)) { $query = "SELECT * FROM usuario WHERE rut = \$1"; $db->exec($query, array(RUT_formatear($_POST['r-rut']))); if ($db->numRows() == 1) { echo "existe"; header('Location: ../login.php?registro=true&error=invalidrut'); } else { $query2 = "INSERT INTO usuario (rut,password,nombre,apellido,email,rol) VALUES (\$1,\$2,\$3,\$4,\$5,\$6)"; echo $query2; $db->exec($query2, array(RUT_formatear($_POST['r-rut']), $_POST['rpasswd'], $_POST['rname'], $_POST['rapellido'], $_POST['remail'], 1)); header('Location: ../login.php?registrado=true'); } } else { header('Location: ../login.php?registro=true'); } function RUT_formatear($rut) { return $rut_formato = str_replace('.', '', substr($rut, 0, -2)); }
<?php require_once "../include/db.php"; # Permite la comunicación con la bd # Se hace la conexión a la BD # $db = new phpDB(); # La variable $db guarda la referencia a la BD $db->connect(); # Se hacen distintas cosas dependiendo del valor del parámetro "action" # if ($_GET['action'] == 'login') { $query = "SELECT * FROM usuario WHERE rut = \$1 and password = \$2"; $db->exec($query, array(RUT_formatear($_POST['rut']), $_POST['password'])); # Si hay un resultado, el login fue correcto # if ($db->numRows() == 1) { session_start(); $_SESSION['user_bd13'] = $db->fobject(); $db->close(); if ($_SESSION['user_bd13']->rol == '0') { header('Location: ../login_cajero.php'); } else { header('Location: ../index.php'); # Redirecciona a /index.php } } else { header('Location: ../login.php?error=true'); # Redirecciona al login con error } } else { if ($_GET['action'] == 'logout') { $db->close(); session_start();