Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. <?php
  2. define('DB_SERVER', 'localhost:3036');
  3. define('DB_USERNAME', 'root');
  4. define('DB_PASSWORD', 'rootpassword');
  5. define('DB_DATABASE', 'database');
  6. $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
  7. ?>
  8.  
  9.  
  10.  
  11.  
  12. <?php
  13. include("config.php");
  14. session_start();
  15.  
  16. if($_SERVER["REQUEST_METHOD"] == "POST") {
  17. // username and password sent from form
  18.  
  19. $myusername = mysqli_real_escape_string($db,$_POST['username']);
  20. $mypassword = mysqli_real_escape_string($db,$_POST['password']);
  21.  
  22. $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
  23. $result = mysqli_query($db,$sql);
  24. $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  25. $active = $row['active'];
  26.  
  27. $count = mysqli_num_rows($result);
  28.  
  29. // If result matched $myusername and $mypassword, table row must be 1 row
  30.  
  31. if($count == 1) {
  32. session_register("myusername");
  33. $_SESSION['login_user'] = $myusername;
  34.  
  35. header("location: welcome.php");
  36. }else {
  37. $error = "Your Login Name or Password is invalid";
  38. }
  39. }
  40. ?>
  41. <html>
  42.  
  43. <head>
  44. <title>Login Page</title>
  45.  
  46. <style type = "text/css">
  47. body {
  48. font-family:Arial, Helvetica, sans-serif;
  49. font-size:14px;
  50. }
  51. label {
  52. font-weight:bold;
  53. width:100px;
  54. font-size:14px;
  55. }
  56. .box {
  57. border:#666666 solid 1px;
  58. }
  59. </style>
  60.  
  61. </head>
  62.  
  63. <body bgcolor = "#FFFFFF">
  64.  
  65. <div align = "center">
  66. <div style = "width:300px; border: solid 1px #333333; " align = "left">
  67. <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
  68.  
  69. <div style = "margin:30px">
  70.  
  71. <form action = "" method = "post">
  72. <label>UserName :</label><input type = "text" name = "username" class = "box"/><br /><br />
  73. <label>Password :</label><input type = "password" name = "password" class = "box" /><br/><br />
  74. <input type = "submit" value = " Submit "/><br />
  75. </form>
  76.  
  77. <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
  78.  
  79. </div>
  80.  
  81. </div>
  82.  
  83. </div>
  84.  
  85. </body>
  86. </html>
  87.  
  88.  
  89.  
  90.  
  91. <?php
  92. include('session.php');
  93. ?>
  94. <html">
  95.  
  96. <head>
  97. <title>Welcome </title>
  98. </head>
  99.  
  100. <body>
  101. <h1>Welcome <?php echo $login_session; ?></h1>
  102. <h2><a href = "logout.php">Sign Out</a></h2>
  103. </body>
  104.  
  105. </html>
  106.  
  107.  
  108.  
  109.  
  110. <?php
  111. include('session.php');
  112. ?>
  113. <html">
  114.  
  115. <head>
  116. <title>Welcome </title>
  117. </head>
  118.  
  119. <body>
  120. <h1>Welcome <?php echo $login_session; ?></h1>
  121. <h2><a href = "logout.php">Sign Out</a></h2>
  122. </body>
  123.  
  124. </html>
  125.  
  126.  
  127.  
  128.  
  129. <?php
  130. include('config.php');
  131. session_start();
  132.  
  133. $user_check = $_SESSION['login_user'];
  134.  
  135. $ses_sql = mysqli_query($db,"select username from admin where username = '$user_check' ");
  136.  
  137. $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
  138.  
  139. $login_session = $row['username'];
  140.  
  141. if(!isset($_SESSION['login_user'])){
  142. header("location:login.php");
  143. die();
  144. }
  145. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement