Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2.  
  3. define('DB_SERVER', 'localhost:3306');
  4. define('DB_USERNAME', 'root');
  5. define('DB_PASSWORD', 'password1');
  6. define('DB_DATABASE', 'db');
  7. $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
  8.  
  9. session_start();
  10.  
  11. if($_SERVER["REQUEST_METHOD"] == "POST") {
  12. // username and password sent from form
  13.  
  14. $myusername = mysqli_real_escape_string($db,$_POST['username']);
  15. $mypassword = mysqli_real_escape_string($db,$_POST['password']);
  16.  
  17. $sql = "SELECT id FROM clients WHERE username = '$myusername' and password = '$mypassword'";
  18. $result = mysqli_query($db,$sql);
  19. $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  20. $active = $row['active'];
  21.  
  22. $count = mysqli_num_rows($result);
  23.  
  24. // If result matched $myusername and $mypassword, table row must be 1 row
  25.  
  26. if($count == 1) {
  27. session_register("myusername");
  28. $_SESSION['login_user'] = $myusername;
  29.  
  30. header("location: welcome.php");
  31. }else {
  32. $error = "Your Login Name or Password is invalid";
  33. }
  34. }
  35. ?>
  36. <html>
  37.  
  38. <head>
  39. <title>Login Page</title>
  40.  
  41. <style type = "text/css">
  42. body {
  43. font-family:Arial, Helvetica, sans-serif;
  44. font-size:14px;
  45. }
  46.  
  47. label {
  48. font-weight:bold;
  49. width:100px;
  50. font-size:14px;
  51. }
  52.  
  53. .box {
  54. border:#666666 solid 1px;
  55. }
  56. </style>
  57.  
  58. </head>
  59.  
  60. <body bgcolor = "#FFFFFF">
  61.  
  62. <div align = "center">
  63. <div style = "width:300px; border: solid 1px #333333; " align = "left">
  64. <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
  65.  
  66. <div style = "margin:30px">
  67.  
  68. <form action = "" method = "post">
  69. <label>UserName :</label><input type = "text" name = "username" class = "box"/><br /><br />
  70. <label>Password :</label><input type = "password" name = "password" class = "box" /><br/><br />
  71. <input type = "submit" value = " Submit "/><br />
  72. </form>
  73.  
  74. <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
  75.  
  76. </div>
  77.  
  78. </div>
  79.  
  80. </div>
  81.  
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement