Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. This is the login.php
  2.  
  3.  
  4.  
  5.  
  6.  
  7. <?php
  8.  
  9. require 'addons/config.php';
  10. session_start();
  11. if(isset($_POST['submit'])){
  12.  
  13. $username = $_POST['username'];
  14. $username = mysqli_real_escape_string($conn, $username);
  15.  
  16. $password = $_POST['password'];
  17. $password = mysqli_real_escape_string($conn, $password);
  18.  
  19. $query = "SELECT * FROM users WHERE username='$username' AND password='".md5($password)."'";
  20. $result = mysqli_query($conn, $query) or die (mysqli_error());
  21. $rows = mysqli_num_rows($result);
  22. if($rows==1){
  23. $_SESSION['username'] = $username;
  24. $_POST['email'] = $email;
  25. header("location: dashboard/home.php");
  26. }else{
  27. header("location: error/log_error.php");
  28. }
  29. }
  30.  
  31.  
  32. ?>
  33.  
  34.  
  35. <button onclick="document.getElementById('id02').style.display='block'" style="width:auto;">Login</button>
  36.  
  37. <div id="id02" class="modal">
  38.  
  39. <form class="modal-content animate" action="#" method="post">
  40.  
  41. <div class="container">
  42. <label><b>Username</b></label>
  43. <input type="text" placeholder="Enter Username" name="username" required>
  44.  
  45. <label><b>Password</b></label>
  46. <input type="password" placeholder="Enter Password" name="password" required>
  47.  
  48. <button type="submit" name="submit" value="login">Login</button>
  49. <input type="checkbox" checked="checked"> Remember me
  50. </div>
  51.  
  52. <div class="container" style="background-color:#f1f1f1">
  53. <button type="button" onclick="document.getElementById('id02').style.display='none'" class="cancelbtn">Cancel</button>
  54. </div>
  55. </form>
  56. </div>
  57.  
  58. <script>
  59. // Get the modal
  60. var modal = document.getElementById('id02');
  61.  
  62. // When the user clicks anywhere outside of the modal, close it
  63. window.onclick = function(event) {
  64. if (event.target == modal) {
  65. modal.style.display = "none";
  66. }
  67. }
  68. </script>
  69.  
  70. <?php
  71. include '../addons/config.php';
  72. include ('../inc/auth.php');
  73.  
  74. ?>
  75.  
  76. <p>Welcome back <?php echo $_SESSION['username']; ?>!</p>
  77. <p>Your email is <?php echo $_POST['email']; ?>!</p>
  78.  
  79.  
  80.  
  81.  
  82.  
  83. <a href="../addons/logout.php">Log off</a>
  84.  
  85. <?php
  86. session_start();
  87. if(!isset($_SESSION["username"])){
  88. header("Location: ../index.php");
  89. exit();
  90. }
  91. ?>
  92.  
  93. <?php
  94.  
  95.  
  96. #
  97.  
  98. // Create connection
  99. $conn = mysqli_connect("localhost", "root", "", "database");
  100. // Check connection
  101.  
  102. if($conn->connect_error){
  103. die("Can`t connect to database: " . $conn->connect_error);
  104. }
  105.  
  106.  
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement