Last active
June 7, 2019 03:41
-
-
Save putheakhem/77204b3586a56d3b89479da54ffd5cec to your computer and use it in GitHub Desktop.
Login form with PHP7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| Author: Khem Puthea | |
| @2019-June-06 | |
| --> | |
| <?php | |
| ob_start(); | |
| session_start(); | |
| ?> | |
| <? | |
| // error_reporting(E_ALL); | |
| // ini_set("display_errors", 1); | |
| ?> | |
| <html lang = "en"> | |
| <head> | |
| <title>Login System</title> | |
| <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | |
| <style> | |
| body { | |
| padding-top: 40px; | |
| padding-bottom: 40px; | |
| background-color: #ADABAB; | |
| } | |
| .form-signin { | |
| max-width: 330px; | |
| padding: 15px; | |
| margin: 0 auto; | |
| color: #017572; | |
| } | |
| .form-signin .form-signin-heading, | |
| .form-signin .checkbox { | |
| margin-bottom: 10px; | |
| } | |
| .form-signin .checkbox { | |
| font-weight: normal; | |
| } | |
| .form-signin .form-control { | |
| position: relative; | |
| height: auto; | |
| -webkit-box-sizing: border-box; | |
| -moz-box-sizing: border-box; | |
| box-sizing: border-box; | |
| padding: 10px; | |
| font-size: 16px; | |
| } | |
| .form-signin .form-control:focus { | |
| z-index: 2; | |
| } | |
| .form-signin input[type="email"] { | |
| margin-bottom: -1px; | |
| border-bottom-right-radius: 0; | |
| border-bottom-left-radius: 0; | |
| border-color:#017572; | |
| } | |
| .form-signin input[type="password"] { | |
| margin-bottom: 10px; | |
| border-top-left-radius: 0; | |
| border-top-right-radius: 0; | |
| border-color:#017572; | |
| } | |
| h2{ | |
| text-align: center; | |
| color: #017572; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h2>Enter Username and Password</h2> | |
| <div class = "container form-signin"> | |
| <?php | |
| $msg = ''; | |
| if (isset($_POST['login']) && !empty($_POST['username']) | |
| && !empty($_POST['password'])) { | |
| if ($_POST['username'] == 'putheakhem' && | |
| $_POST['password'] == '123456') { | |
| $_SESSION['valid'] = true; | |
| $_SESSION['timeout'] = time(); | |
| $_SESSION['username'] = 'putheakhem'; | |
| echo 'You have entered valid use name and password'; | |
| }else { | |
| $msg = 'Wrong username or password'; | |
| } | |
| } | |
| ?> | |
| </div> <!-- /container --> | |
| <div class = "container"> | |
| <form class = "form-signin" role = "form" | |
| action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']); | |
| ?>" method = "post"> | |
| <h4 class = "form-signin-heading"><?php echo $msg; ?></h4> | |
| <input type = "text" class = "form-control" | |
| name = "username" placeholder = "username = putheakhem" | |
| required autofocus></br> | |
| <input type = "password" class = "form-control" | |
| name = "password" placeholder = "password = 123456" required> | |
| <button class = "btn btn-lg btn-primary btn-block" type = "submit" | |
| name = "login">Login</button> | |
| </form> | |
| Click here to clean <a href = "logout.php" tite = "Logout">Session. | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment