23.-Crear área de login de nuestro ecommerce en PHP
En este tutorial vamos crear área de login de nuestro ecommerce en PHP pero lo vamos a copiar del área del admin.
Codigo: https://github.com/programadornovato/ecommerce/commit/6370c3a311e2537265e1640fae9434199c33e00b
index.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>My ecommerce by pn</title> <!-- Tell the browser to be responsive to screen width --> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Font Awesome --> <link rel="stylesheet" href="admin/plugins/fontawesome-free/css/all.min.css"> <!-- Ionicons --> <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <!-- Theme style --> <link rel="stylesheet" href="admin/dist/css/adminlte.min.css"> <!-- Daterange picker --> <link rel="stylesheet" href="admin/plugins/daterangepicker/daterangepicker.css"> <!-- Google Font: Source Sans Pro --> <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet"> <?php session_start(); $accion=$_REQUEST['accion']??''; if($accion=='cerrar'){ session_destroy(); header("Refresh:0"); } ?> </head> <body> <?php include_once "admin/db_ecommerce.php"; $con = mysqli_connect($host, $user, $pass, $db); ?> <div class="container"> <div class="row"> <div class="col-12"> <?php include_once "menu.php"; $modulo=$_REQUEST['modulo']??''; if($modulo=="productos" || $modulo=="" ){ include_once "productos.php"; } if( $modulo=="detalleproducto" ){ include_once "detalleProducto.php"; } if( $modulo=="carrito" ){ include_once "carrito.php"; } ?> </div> </div> </div> <!-- jQuery --> <script src="admin/plugins/jquery/jquery.min.js"></script> <!-- jQuery UI 1.11.4 --> <script src="admin/plugins/jquery-ui/jquery-ui.min.js"></script> <!-- Bootstrap 4 --> <script src="admin/plugins/bootstrap/js/bootstrap.bundle.min.js"></script> <!-- daterangepicker --> <script src="admin/plugins/moment/moment.min.js"></script> <script src="admin/plugins/daterangepicker/daterangepicker.js"></script> <!-- AdminLTE App --> <script src="admin/dist/js/adminlte.js"></script> <!-- AdminLTE dashboard demo (This is only for demo purposes) --> <script src="admin/dist/js/pages/dashboard.js"></script> <script src="admin/js/ecommerce.js"></script> </body> </html>
login.php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>My ecommerce</title> <!-- Tell the browser to be responsive to screen width --> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Font Awesome --> <link rel="stylesheet" href="admin/plugins/fontawesome-free/css/all.min.css"> <!-- Ionicons --> <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <!-- icheck bootstrap --> <link rel="stylesheet" href="admin/plugins/icheck-bootstrap/icheck-bootstrap.min.css"> <!-- Theme style --> <link rel="stylesheet" href="admin/dist/css/adminlte.min.css"> <!-- Google Font: Source Sans Pro --> <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet"> </head> <body class="hold-transition login-page"> <div class="login-box"> <div class="login-logo"> <b>My</b>ecommerce </div> <!-- /.login-logo --> <div class="card"> <div class="card-body login-card-body"> <p class="login-box-msg">Logueate</p> <?php if (isset($_REQUEST['login'])) { session_start(); $email = $_REQUEST['email'] ?? ''; $pasword = $_REQUEST['pass'] ?? ''; $pasword = md5($pasword); include_once "admin/db_ecommerce.php"; $con = mysqli_connect($host, $user, $pass, $db); $query = "SELECT id,email,nombre from clientes where email='" . $email . "' and pass='" . $pasword . "'; "; $res = mysqli_query($con, $query); $row = mysqli_fetch_assoc($res); if ($row) { $_SESSION['idCliente'] = $row['id']; $_SESSION['emailCliente'] = $row['email']; $_SESSION['nombreCliente'] = $row['nombre']; header("location: index.php?mensaje=Usuario registrado exitosamente"); } else { ?> <div class="alert alert-danger" role="alert"> Error de login <img src="admin/images/haha.jpg" width="200"> </div> <?php } } ?> <form method="post"> <div class="input-group mb-3"> <input type="email" class="form-control" placeholder="Email" name="email"> <div class="input-group-append"> <div class="input-group-text"> <span class="fas fa-envelope"></span> </div> </div> </div> <div class="input-group mb-3"> <input type="password" class="form-control" placeholder="Password" name="pass"> <div class="input-group-append"> <div class="input-group-text"> <span class="fas fa-lock"></span> </div> </div> </div> <div class="row"> <!-- /.col --> <div class="col-12"> <button type="submit" class="btn btn-primary" name="login">Loguearse</button> <a href="registro.php" class="text-success float-right" >Registrarse</a> </div> <!-- /.col --> </div> </form> <!-- /.login-card-body --> </div> </div> <!-- /.login-box --> <!-- jQuery --> <script src="admin/plugins/jquery/jquery.min.js"></script> <!-- Bootstrap 4 --> <script src="admin/plugins/bootstrap/js/bootstrap.bundle.min.js"></script> <!-- AdminLTE App --> <script src="admin/dist/js/adminlte.min.js"></script> </body> </html>
menu.php
<!-- Navbar --> <nav class="navbar navbar-expand navbar-dark"> <!-- Left navbar links --> <ul class="navbar-nav"> <li class="nav-item d-none d-sm-inline-block"> <a href="index.php" class="nav-link">Home</a> </li> <li class="nav-item d-none d-sm-inline-block"> <a href="#" class="nav-link">Contact</a> </li> </ul> <!-- SEARCH FORM --> <form class="form-inline ml-3" action="index.php"> <div class="input-group input-group-sm"> <input class="form-control form-control-navbar bg-gray" type="search" placeholder="Search" aria-label="Search" name="nombre" value="<?php echo $_REQUEST['nombre'] ?? ''; ?>"> <input type="hidden" name="modulo" value="productos"> <div class="input-group-append"> <button class="btn btn-navbar" type="submit"> <i class="fas fa-search"></i> </button> </div> </div> </form> <!-- Right navbar links --> <ul class="navbar-nav ml-auto"> <!-- Messages Dropdown Menu --> <li class="nav-item dropdown"> <a class="nav-link" data-toggle="dropdown" href="#" id="iconoCarrito"> <i class="fa fa-cart-plus" aria-hidden="true"></i> <span class="badge badge-danger navbar-badge" id="badgeProducto"></span> </a> <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right" id="listaCarrito"> </div> </li> <!-- Notifications Dropdown Menu --> <li class="nav-item dropdown"> <a class="nav-link" data-toggle="dropdown" href="#"> <i class="fa fa-user" aria-hidden="true"></i> </a> <div class="dropdown-menu dropdown-menu-md dropdown-menu-right"> <?php if (isset($_SESSION['idCliente']) == false) { ?> <a href="login.php" class="dropdown-item"> <i class="fas fa-door-open mr-2 text-primary"></i>Loguearse </a> <div class="dropdown-divider"></div> <a href="registro.php" class="dropdown-item"> <i class="fas fa-sign-in-alt mr-2 text-primary"></i>Registrarse </a> <?php } else { ?> <a href="index.php?modulo=usuario" class="dropdown-item"> <i class="fas fa-user text-primary mr-2"></i>Hola <?php echo $_SESSION['nombreCliente']; ?> </a> <form action="index.php" method="post"> <button name="accion" class="btn btn-danger dropdown-item" type="submit" value="cerrar"> <i class="fas fa-door-closed text-danger mr-2"></i>Cerrar sesion </button> </form> <?php } ?> </div> </li> </ul> </nav> <?php $mensaje = $_REQUEST['mensaje'] ?? ''; if ($mensaje) { ?> <div class="alert alert-primary alert-dismissible fade show" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> <span class="sr-only">Close</span> </button> <?php echo $mensaje; ?> </div> <?php } ?>
🎦Curso de PHP🐘 y MySql🐬: https://www.youtube.com/playlist?list=PLCTD_CpMeEKS2Dvb-WNrAuDAXObB8GzJ0
🎦[Curso] Laravel Tutorial en Español: https://www.youtube.com/playlist?list=PLCTD_CpMeEKQcVcM4u4qddLYRE37S_0XS
🎦Curso]Ajax con Jquery de 0 a 100 🌇: https://www.youtube.com/watch?v=52yI0xiB73A&list=PLCTD_CpMeEKSYJ1J15M8PknOMwOpeqsXz
🎦Mysql configurar una replicación maestro – esclavo 🐬: https://www.youtube.com/watch?v=RY-EdBOJWEs
🎦[Curso] Visual Studio Code 🆚 de 0 a 100: https://www.youtube.com/playlist?list=PLCTD_CpMeEKQbdlT8efsS-veXuvYZ1UWn
🎦[Curso] Bootstrap de 0 a 100 🌈: https://www.youtube.com/playlist?list=PLCTD_CpMeEKSVmsZJIumVvfDviuW-c9AT
🎦[Curso] HTML y CSS de 0 a 100 🌐: https://www.youtube.com/playlist?list=PLCTD_CpMeEKS1SmufBGPOV1mjNfCiLwek
🎦 Esta lista de reproducción: https://www.youtube.com/playlist?list=PLCTD_CpMeEKQhRiJx7Wv3pM3rYvT9_CS9 .
Codigos en gdrive: https://drive.google.com/file/d/1QW8ExkL8eS7nQ5HTDvUuSkkGJMSmecGV/view?usp=sharing
Gracias por apoyar este canal: https://www.patreon.com/programadornovato?fan_landing=true
🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial
🔗 Twitter: https://twitter.com/programadornova
🔗 Linkedin: https://www.linkedin.com/in/programadornovato/
🔗 Instagram: https://www.instagram.com/programadornovato/
<<Anterior tutorial Siguiente tutorial >>
Ave que vuela, a la cazuela.