INICIAR SESION

 Creamos un login con variables de sesion.





<?php

require_once "models/conexion.php";

class ModeloFormularios extends Conexion{

/*=============================================

Seleccionar Registros

=============================================*/

static public function mdlSeleccionarRegistros($tabla, $item, $valor){

    $stmt = Conexion::conectar()->prepare("SELECT * FROM $tabla WHERE $item = :$item ORDER                   BY id_usuario DESC");

    $stmt->bindParam($item, $valor, PDO::PARAM_STR);

    $stmt->execute();

    return $stmt->fetch(); // Cambiado a fetchAll()

}

}

?>

<div class="container w-25" style="background-color: white;">

<form method="POST">

  <div class="mb-3">

    <label for="exampleInputEmail1" class="form-label">Correo electrónico</label>

    <input type="text" class="form-control" name="usernameingreso" >

  </div>

  <div class="mb-3">

    <label for="exampleInputPassword1" class="form-label">Contraseña</label>

    <input type="password" class="form-control" name="passwordingreso" >

  </div>

  <button type="submit" class="btn btn-primary">Enviar</button>

</form>

<?php 

$ingreso = new ControladorFormularios();

$ingreso -> ctrIngreso();

?>

</div>

<?php

class ControladorFormularios{

/*=============================================

Ingreso

=============================================*/

public function ctrIngreso(){

if(isset($_POST["usernameingreso"])){

$tabla = "usuarios";

$item = "username";

$valor = $_POST["usernameingreso"];

$respuesta = ModeloFormularios::mdlSeleccionarRegistros($tabla, $item, $valor);

if($respuesta["username"] == $_POST["usernameingreso"] && $respuesta["password"] == $_POST["passwordingreso"]){

$_SESSION["validarIngreso"] = "ok";

echo '<script>

if ( window.history.replaceState ) {

window.history.replaceState( null, null, window.location.href );

}

window.location = "index.php?pagina=inicio";

</script>';

}else{

echo '<script>

if ( window.history.replaceState ) {

window.history.replaceState( null, null, window.location.href );

}

</script>';

echo '<div class="alert alert-danger">Error al ingresar al sistema, el email o la contraseña no coinciden</div>';

}

}

}

}

?>


Comentarios

Entradas populares de este blog

Filtrando por fecha

10 videojuegos gratis para aprender JavaScript en línea

reloj obs---datetime.lua