Guest User

Untitled

a guest
Feb 2nd, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.23 KB | None | 0 0
  1. <?php
  2. //check if session id is set. If it is not set, user will be redirected back to login page
  3.  
  4. if(!isset($_SESSION['username'])){
  5. header('Location:index.php');
  6. die();
  7. }
  8. ?>
  9.  
  10. <?php
  11. //PHP method to use cache memory to store details
  12. session_start();
  13. //Makes the "config.php" file available to be executed from this page
  14. require_once('dbconfig/config.php');
  15. ?>
  16. <!DOCTYPE html>
  17. <html>
  18. <head>
  19. <!-- Site title, CSS external file and font awesome -->
  20. <title>Login Page - Created by Liam Docherty</title>
  21. <link rel="stylesheet" href="css/design.css">
  22. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
  23. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  24. </head>
  25. <body>
  26. <div id="main-wrapper">
  27. <center>
  28. <h2>Login Form - Created by Liam Docherty</h2>
  29. </center>
  30. <div class="imgcontainer">
  31. <img src="imgs/icon-person-512.png" alt="Avatar" class="avatar">
  32. </div>
  33. <!-- THE FORM -->
  34. <!-- action="index.php" -- This attribute shows where the PHP script that does the processing is located -->
  35. <!-- method="post" -- The attribute identifies the action that will be performed with the data of the form. I.E. POST data to the "users" database -->
  36. <form action="index.php" method="post">
  37. <div class="inner_container">
  38. <label><b>Username</b></label>
  39. <input type="text" placeholder="Enter Username" name="username" required>
  40. <label><b>Password</b></label>
  41. <input type="password" placeholder="Enter Password" name="password" required>
  42. <!-- The Login button -->
  43. <button class="login_button" name="login" type="submit">Login</button>
  44. <!-- The button that is linked to the "register.php" page -->
  45. <a href="register.php"><button type="button" class="register_btn">Register</button></a>
  46. </div>
  47. </form>
  48. <?php
  49. //Condition, checking the Login button is pressed
  50. if(isset($_POST['login']))
  51. {
  52. //The data from the Form (username & password) is stored into the @$username & @$passwordVariables
  53. //You use @ before a VARIABLE in PHP when you do not want to initialise the VARIABLE before using it
  54. @$username=$_POST['username'];
  55. @$password=$_POST['password'];
  56.  
  57. //Statement that will SELECT the data from the "login" table, WHERE the Usename and Password typed match the typed ones
  58. //Once the database is checked, if login details match than it stores the data in the "$query" VARIABLE
  59. $query = "SELECT * FROM login WHERE username='$username' and password='$password' ";
  60. //echo $query;
  61.  
  62. //This statement performs both the connection to the database using the values in the "$con" VARIABLE and
  63. //The SELECT statement stored in the "$query" VARIABLE
  64. $query_run = mysqli_query($con,$query);
  65. //echo mysql_num_rows($query_run);
  66.  
  67. //IF the "$query_run" is run successfully, then
  68. if($query_run)
  69. {
  70. //Check if the Username and Password exist in the database, if they exist
  71. if(mysqli_num_rows($query_run)>0)
  72. {
  73. $row = mysqli_fetch_array($query_run,MYSQLI_ASSOC);
  74.  
  75. $_SESSION['username'] = $username;
  76. $_SESSION['password'] = $password;
  77.  
  78. //Sent the user to the "homepage.php" page
  79. header( "Location: homepage.php");
  80. }
  81. else
  82. {
  83. //IF NOT, Display the message below
  84. echo '<script type="text/javascript">alert("No such User exists. Invalid Credentials")</script>';
  85. }
  86. }
  87.  
  88. //IF the "$query_run" is NOT successful, then
  89. else
  90. {
  91. //Display this message
  92. echo '<script type="text/javascript">alert("Database Error")</script>';
  93. }
  94. }
  95. else
  96. {
  97. }
  98. ?>
  99. </div>
  100. </body>
  101. </html>
  102.  
  103. <?php
  104. //check if session id is set. If it is not set, user will be redirected back to login page
  105.  
  106. if(!isset($_SESSION['username'])){
  107. header('Location:index.php');
  108. die();
  109. }
  110. ?>
  111.  
  112. <!doctype html>
  113. <html lang="en">
  114. <head>
  115. <meta charset="utf-8">
  116. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  117. <meta name="description" content="">
  118. <meta name="author" content="">
  119. <link rel="icon" href="../../../../favicon.ico">
  120. <!-- Site title, CSS external file and font awesome -->
  121. <title>Login Page - Created by Liam Docherty</title>
  122. <link rel="stylesheet" href="css/design.css">
  123. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  124. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
  125. </head>
  126. <body class="bg-white">
  127. <div class="container">
  128. <div class="py-5 text-center">
  129. <img class="d-block mx-auto mb-4" src="https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">
  130. <h2>Checkout form</h2>
  131. <p class="lead">Below is an example form built entirely with Bootstrap's form controls. Each required form group has a validation state that can be triggered by attempting to submit the form without completing it.</p>
  132. </div>
  133. <div class="row">
  134. <div class="col-md-4 order-md-2 mb-4">
  135. <h4 class="d-flex justify-content-between align-items-center mb-3">
  136. <span class="text-muted">Your cart</span>
  137. <span class="badge badge-secondary badge-pill">3</span>
  138. </h4>
  139. <ul class="list-group mb-3">
  140. <li class="list-group-item d-flex justify-content-between lh-condensed">
  141. <div>
  142. <h6 class="my-0">Product name</h6>
  143. <small class="text-muted">Brief description</small>
  144. </div>
  145. <span class="text-muted">$12</span>
  146. </li>
  147. <li class="list-group-item d-flex justify-content-between lh-condensed">
  148. <div>
  149. <h6 class="my-0">Second product</h6>
  150. <small class="text-muted">Brief description</small>
  151. </div>
  152. <span class="text-muted">$8</span>
  153. </li>
  154. <li class="list-group-item d-flex justify-content-between lh-condensed">
  155. <div>
  156. <h6 class="my-0">Third item</h6>
  157. <small class="text-muted">Brief description</small>
  158. </div>
  159. <span class="text-muted">$5</span>
  160. </li>
  161. <li class="list-group-item d-flex justify-content-between bg-light">
  162. <div class="text-success">
  163. <h6 class="my-0">Promo code</h6>
  164. <small>EXAMPLECODE</small>
  165. </div>
  166. <span class="text-success">-$5</span>
  167. </li>
  168. <li class="list-group-item d-flex justify-content-between">
  169. <span>Total (USD)</span>
  170. <strong>$20</strong>
  171. </li>
  172. </ul>
  173. <form class="card p-2">
  174. <div class="input-group">
  175. <input type="text" class="form-control" placeholder="Promo code">
  176. <div class="input-group-append">
  177. <button type="submit" class="btn btn-secondary">Redeem</button>
  178. </div>
  179. </div>
  180. </form>
  181. </div>
  182. <div class="col-md-8 order-md-1">
  183. <h4 class="mb-3">Billing address</h4>
  184. <form class="needs-validation" novalidate>
  185. <div class="row">
  186. <div class="col-md-6 mb-3">
  187. <label for="firstName">First name</label>
  188. <input type="text" class="form-control" id="firstName" placeholder="" value="" required>
  189. <div class="invalid-feedback">
  190. Valid first name is required.
  191. </div>
  192. </div>
  193. <div class="col-md-6 mb-3">
  194. <label for="lastName">Last name</label>
  195. <input type="text" class="form-control" id="lastName" placeholder="" value="" required>
  196. <div class="invalid-feedback">
  197. Valid last name is required.
  198. </div>
  199. </div>
  200. </div>
  201. <div class="mb-3">
  202. <label for="username">Username</label>
  203. <div class="input-group">
  204. <div class="input-group-prepend">
  205. <span class="input-group-text">@</span>
  206. </div>
  207. <input type="text" class="form-control" id="username" placeholder="Username" required>
  208. <div class="invalid-feedback" style="width: 100%;">
  209. Your username is required.
  210. </div>
  211. </div>
  212. </div>
  213. <div class="mb-3">
  214. <label for="email">Email <span class="text-muted">(Optional)</span></label>
  215. <input type="email" class="form-control" id="email" placeholder="you@example.com">
  216. <div class="invalid-feedback">
  217. Please enter a valid email address for shipping updates.
  218. </div>
  219. </div>
  220. <div class="mb-3">
  221. <label for="address">Address</label>
  222. <input type="text" class="form-control" id="address" placeholder="34 Hoxton liam street" required>
  223. <div class="invalid-feedback">
  224. Please enter your shipping address.
  225. </div>
  226. </div>
  227. <div class="row">
  228. <div class="col-md-5 mb-3">
  229. <!-- Logout button -->
  230. <a class="btn btn-primary" href="index.php" role="button">Signout button</a>
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. </body>
  237. </html>
Add Comment
Please, Sign In to add comment