Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if( isset($_POST['user_id'])){
- header('location: members_1.php');
- }
- $user = [
- 'id' => '16',
- 'name' => 'Ivan',
- 'email' => 'mr@gmail.com',
- 'password' => '12345',
- ];
- $error = '';
- if (isset($_POST['submit'])) {
- $email = !empty($_POST['email']) ? trim($_POST['email']) : '';
- $password = !empty($_POST['password']) ? trim($_POST['password']) : '';
- $emailRegex = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
- if (!$email || !preg_match($emailRegex, $email)) {
- $error = ' * Email field must contain a valid email address';
- }elseif (! $password) {
- $error = ' * Password field must contain a valid password';
- } elseif($user['email'] != $email || $user['password'] != $password){
- $error = ' * Email or Password is not valid';
- }else{
- if(isset($_POST['rem-me'])){
- setcookie(session_name(), session_id(), time() + 60*60*24*365, '/');
- }
- $_SESSION['user_id'] = $user['id'];
- $_SESSION['user_name'] = $user['name'];
- header('location: members_1.php');
- }
- }
- function old($field_name){
- return isset($_POST[$field_name]) ? $_POST[$field_name] : '';
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Sign in page</title>
- <style>
- span.error {
- color: #797979;
- font-family: fantasy;
- }
- .form-style-8{
- font-family: 'Open Sans Condensed', arial, sans;
- width: 500px;
- padding: 30px;
- background: #FFFFFF;
- margin: 50px auto;
- box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.22);
- -moz-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.22);
- -webkit-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.22);
- }
- .form-style-8 h1{
- background: #4D4D4D;
- text-transform: uppercase;
- font-family: 'Open Sans Condensed', sans-serif;
- color: #797979;
- font-size: 18px;
- font-weight: 100;
- padding: 20px;
- margin: -30px -30px 30px -30px;
- }
- .form-style-8 input[type="text"],
- .form-style-8 input[type="date"],
- .form-style-8 input[type="datetime"],
- .form-style-8 input[type="email"],
- .form-style-8 input[type="number"],
- .form-style-8 input[type="search"],
- .form-style-8 input[type="time"],
- .form-style-8 input[type="url"],
- .form-style-8 input[type="password"],
- .form-style-8 textarea,
- .form-style-8 select
- {
- box-sizing: border-box;
- -webkit-box-sizing: border-box;
- -moz-box-sizing: border-box;
- outline: none;
- display: block;
- width: 100%;
- padding: 7px;
- border: none;
- border-bottom: 1px solid #ddd;
- background: transparent;
- margin-bottom: 10px;
- font: 16px Arial, Helvetica, sans-serif;
- height: 45px;
- }
- .form-style-8 textarea{
- resize:none;
- overflow: hidden;
- }
- .form-style-8 input[type="button"],
- .form-style-8 input[type="submit"]{
- -moz-box-shadow: inset 0px 1px 0px 0px #45D6D6;
- -webkit-box-shadow: inset 0px 1px 0px 0px #45D6D6;
- box-shadow: inset 0px 1px 0px 0px #45D6D6;
- background-color: #2CBBBB;
- border: 1px solid #27A0A0;
- display: inline-block;
- cursor: pointer;
- color: #FFFFFF;
- font-family: 'Open Sans Condensed', sans-serif;
- font-size: 14px;
- padding: 8px 18px;
- text-decoration: none;
- text-transform: uppercase;
- }
- .form-style-8 input[type="button"]:hover,
- .form-style-8 input[type="submit"]:hover {
- background:linear-gradient(to bottom, #34CACA 5%, #30C9C9 100%);
- background-color:#34CACA;
- }
- </style>
- </head>
- <body>
- <div class="form-style-8">
- <h1>Sign In</h1>
- <form action="" method="POST">
- <div class="form-set">
- <label for="email">Email:</label>
- <input type="text" name="email" id="email" value="<?= old('email') ?>">
- </div>
- <br><br>
- <div class="form-set">
- <label for="password">Password:</label>
- <input type="password" name="password" id="password">
- </div>
- <br><br>
- <input type="checkbox" name="rem-me" id="rem-me" value="1" checked="checked">
- <label for="rem-me">Remember me</label><br><br>
- <input type="submit" name="submit" value="Sign In">
- <span class="error"><?= $error; ?></span>
- </form>
- </div>
- </body>
- </body>
- </html>
Add Comment
Please, Sign In to add comment