Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ?>
- <!DOCTYPE html>
- <html lang="es">
- <head>
- <meta charset="utf-8">
- <title>Login</title>
- </head>
- <body>
- <div>
- <center>
- <form method="POST" action="validar.php">
- <input type="text" name="nombre" placeholder="Usuario">
- <br>
- <input type="password" name="password" placeholder="Contraseña"><br>
- <button type="submit">Iniciar Sesion</button>
- </form>
- </center>
- </div>
- </body>
- </html>
- <?php
- include 'conex.php';
- $usuario = $_POST['nombre'];
- $pass = $_POST['password'];
- if(empty($usuario) || empty($pass)){
- header("Location: index.php");
- exit();
- }
- $query=("SELECT * FROM usuarios where Username='".$usuario."'");
- echo var_dump($query);
- $res = $con->query($query);
- if($row = mysql_fetch_array($res)){
- if($row['Password'] == $pass){
- session_start();
- $_SESSION['usuario'] = $usuario;
- header("Location: inicio.php");
- }
- else
- {
- header("Location: index.php");
- exit();
- }
- }
- else
- {
- header("Location: index.php");
- exit();
- }
- ?>
- if (empty($usuario) || empty($pass)) {
- header("Location: index.php");
- exit();
- }
- if (!isset($_SESSION)) {
- session_start();
- }
- if (isset($_SESSION['usuario'])) {
- header("Location: inicio.php");
- } else {
- // Sentencias...
- }
- <label id="uno">Inicio de Sesión</label>
- <fieldset style="width:400px" id="cuadro">
- <form action="" method="post">
- <br>
- <label id="dos" for="username">Username: </label><input type="text" id="username" name="username" >
- <br><br>
- <label id="tres"for="pass">Password: </label><input type="password" id="pass" name="pass" >
- <br><br>
- <input type="submit" value="Iniciar Sesión" class="btn btn-primary">   <input type="reset" value="Limpiar" class="btn btn-primary">
- </form>
- </fieldset>
- </center>
- <?php
- if(!empty($_POST['username'])){
- include "Conex.php";
- include "User.php";
- $conex = new ConexionDB;
- $user = User::login(addslashes($_POST['username']),$_POST['pass'],$conex);
- //$userData=$user->getReturn();
- $userData=$user;
- if( !empty($userData) ){
- session_start();
- $_SESSION['user']=$userData;
- header('location:home.php');
- }else{
- echo "<br>";
- echo "<center><h3>Username o password incorrectos!</h3></center>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement