Signup, Login and logout code in PHP for Laser marking website
Advertisement
Here i am sharing source code with you in PHP and MySQL. If you are unaware that how laser marking works, then you can check the detail about laser marking provide by LASIT.
Advertisement
“LASIT is an international company that works with passion and dedication for laser marking and engraving technologies.”
Advertisement
registration.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://projectsinventory.com">Laser marking website</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">PHP login logout for Laser marking website</h3> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-2"></div> <div class="col-md-8"> <form action="register_query.php" method="POST"> <h4 class="text-success">Register here...</h4> <hr style="border-top:1px groovy #000;"> <div class="form-group"> <label>Firstname</label> <input type="text" class="form-control" name="firstname" /> </div> <div class="form-group"> <label>Lastname</label> <input type="text" class="form-control" name="lastname" /> </div> <div class="form-group"> <label>Username</label> <input type="text" class="form-control" name="username" /> </div> <div class="form-group"> <label>Password</label> <input type="password" class="form-control" name="password" /> </div> <br /> <div class="form-group"> <button class="btn btn-primary form-control" name="register">Register</button> </div> <a href="index.php">Login</a> </form> </div> </div> </body> </html> |
logout.php
1 2 3 4 5 |
<?php session_start(); session_destroy(); header('location: index.php'); ?> |
login_query.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?php session_start(); require_once 'conn.php'; if(ISSET($_POST['login'])){ if($_POST['username'] != "" || $_POST['password'] != ""){ $username = $_POST['username']; // md5 encrypted // $password = md5($_POST['password']); $password = $_POST['password']; $sql = "SELECT * FROM `member` WHERE `username`=? AND `password`=? "; $query = $conn->prepare($sql); $query->execute(array($username,$password)); $row = $query->rowCount(); $fetch = $query->fetch(); if($row > 0) { $_SESSION['user'] = $fetch['mem_id']; header("location: home.php"); } else{ echo " <script>alert('Invalid username or password')</script> <script>window.location = 'index.php'</script> "; } }else{ echo " <script>alert('Please complete the required field!')</script> <script>window.location = 'index.php'</script> "; } } ?> |
database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
CREATE TABLE `member` ( `mem_id` int(11) NOT NULL, `firstname` varchar(50) NOT NULL, `lastname` varchar(50) NOT NULL, `username` varchar(30) NOT NULL, `password` varchar(12) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `member` -- INSERT INTO `member` (`mem_id`, `firstname`, `lastname`, `username`, `password`) VALUES (1, 'Administrator', '', 'admin', 'admin'); |
Download Authentication code for Laser Marking website in PHP