Guest User

Untitled

a guest
Jul 10th, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if( isset($_POST['user_id'])){
  6.  
  7. header('location: members_1.php');
  8.  
  9. }
  10.  
  11. $user = [
  12.  
  13. 'id' => '16',
  14. 'name' => 'Ivan',
  15. 'email' => 'mr@gmail.com',
  16. 'password' => '12345',
  17.  
  18. ];
  19.  
  20. $error = '';
  21.  
  22.  
  23. if (isset($_POST['submit'])) {
  24. $email = !empty($_POST['email']) ? trim($_POST['email']) : '';
  25. $password = !empty($_POST['password']) ? trim($_POST['password']) : '';
  26. $emailRegex = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
  27.  
  28. if (!$email || !preg_match($emailRegex, $email)) {
  29. $error = ' * Email field must contain a valid email address';
  30. }elseif (! $password) {
  31. $error = ' * Password field must contain a valid password';
  32. } elseif($user['email'] != $email || $user['password'] != $password){
  33. $error = ' * Email or Password is not valid';
  34. }else{
  35.  
  36. if(isset($_POST['rem-me'])){
  37.  
  38. setcookie(session_name(), session_id(), time() + 60*60*24*365, '/');
  39.  
  40. }
  41.  
  42. $_SESSION['user_id'] = $user['id'];
  43. $_SESSION['user_name'] = $user['name'];
  44. header('location: members_1.php');
  45. }
  46. }
  47.  
  48. function old($field_name){
  49. return isset($_POST[$field_name]) ? $_POST[$field_name] : '';
  50. }
  51.  
  52. ?>
  53. <!DOCTYPE html>
  54. <html>
  55. <head>
  56. <meta charset="UTF-8">
  57. <title>Sign in page</title>
  58. <style>
  59. span.error {
  60. color: #797979;
  61. font-family: fantasy;
  62. }
  63. .form-style-8{
  64. font-family: 'Open Sans Condensed', arial, sans;
  65. width: 500px;
  66. padding: 30px;
  67. background: #FFFFFF;
  68. margin: 50px auto;
  69. box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.22);
  70. -moz-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.22);
  71. -webkit-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.22);
  72.  
  73. }
  74. .form-style-8 h1{
  75. background: #4D4D4D;
  76. text-transform: uppercase;
  77. font-family: 'Open Sans Condensed', sans-serif;
  78. color: #797979;
  79. font-size: 18px;
  80. font-weight: 100;
  81. padding: 20px;
  82. margin: -30px -30px 30px -30px;
  83. }
  84. .form-style-8 input[type="text"],
  85. .form-style-8 input[type="date"],
  86. .form-style-8 input[type="datetime"],
  87. .form-style-8 input[type="email"],
  88. .form-style-8 input[type="number"],
  89. .form-style-8 input[type="search"],
  90. .form-style-8 input[type="time"],
  91. .form-style-8 input[type="url"],
  92. .form-style-8 input[type="password"],
  93. .form-style-8 textarea,
  94. .form-style-8 select
  95. {
  96. box-sizing: border-box;
  97. -webkit-box-sizing: border-box;
  98. -moz-box-sizing: border-box;
  99. outline: none;
  100. display: block;
  101. width: 100%;
  102. padding: 7px;
  103. border: none;
  104. border-bottom: 1px solid #ddd;
  105. background: transparent;
  106. margin-bottom: 10px;
  107. font: 16px Arial, Helvetica, sans-serif;
  108. height: 45px;
  109. }
  110. .form-style-8 textarea{
  111. resize:none;
  112. overflow: hidden;
  113. }
  114. .form-style-8 input[type="button"],
  115. .form-style-8 input[type="submit"]{
  116. -moz-box-shadow: inset 0px 1px 0px 0px #45D6D6;
  117. -webkit-box-shadow: inset 0px 1px 0px 0px #45D6D6;
  118. box-shadow: inset 0px 1px 0px 0px #45D6D6;
  119. background-color: #2CBBBB;
  120. border: 1px solid #27A0A0;
  121. display: inline-block;
  122. cursor: pointer;
  123. color: #FFFFFF;
  124. font-family: 'Open Sans Condensed', sans-serif;
  125. font-size: 14px;
  126. padding: 8px 18px;
  127. text-decoration: none;
  128. text-transform: uppercase;
  129. }
  130. .form-style-8 input[type="button"]:hover,
  131. .form-style-8 input[type="submit"]:hover {
  132. background:linear-gradient(to bottom, #34CACA 5%, #30C9C9 100%);
  133. background-color:#34CACA;
  134. }
  135.  
  136. </style>
  137. </head>
  138. <body>
  139. <div class="form-style-8">
  140. <h1>Sign In</h1>
  141. <form action="" method="POST">
  142. <div class="form-set">
  143. <label for="email">Email:</label>
  144. <input type="text" name="email" id="email" value="<?= old('email') ?>">
  145. </div>
  146. <br><br>
  147. <div class="form-set">
  148. <label for="password">Password:</label>
  149. <input type="password" name="password" id="password">
  150. </div>
  151. <br><br>
  152. <input type="checkbox" name="rem-me" id="rem-me" value="1" checked="checked">
  153. <label for="rem-me">Remember me</label><br><br>
  154. <input type="submit" name="submit" value="Sign In">
  155. <span class="error"><?= $error; ?></span>
  156. </form>
  157. </div>
  158. </body>
  159. </body>
  160. </html>
Add Comment
Please, Sign In to add comment