Advertisement
Guest User

login

a guest
May 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['login_btn']))
  3. {
  4. setcookie("uid",$_POST['username'],time()+60*60*7);
  5. setcookie("uiid",$_POST['password'],time()+60*60*7);
  6. }
  7. session_start();
  8.  
  9. if(!isset($_COOKIE['uid']))
  10. {
  11. $temp="";
  12. $temp1="";
  13. }
  14. else
  15. {
  16. $temp=$_COOKIE['uid'] ;
  17. $temp1=$_COOKIE['uiid'];
  18.  
  19. }
  20.  
  21. $db= mysqli_connect("localhost","root","","authentication");
  22. if(isset($_POST['login_btn']))
  23. {
  24.  
  25. $username=mysqli_real_escape_string($db,$_POST['username']);
  26.  
  27. $password=mysqli_real_escape_string($db,$_POST['password']);
  28. $password=md5($password);
  29. $sql="select * from users where username='$username' and password='$password'";
  30. $result=mysqli_query($db,$sql);
  31.  
  32. if(mysqli_num_rows($result)==1)
  33. {
  34. $_SESSION['message']="Logged In";
  35. $_SESSION['username']=$username;
  36. header("location:hme.php");
  37. }
  38. else
  39. {
  40. $_SESSION['message']="Password/Username incorrect";
  41. }
  42.  
  43.  
  44. }
  45.  
  46. ?>
  47.  
  48.  
  49. <!DOCTYPE html>
  50. <html >
  51. <head>
  52. <meta charset="UTF-8">
  53.  
  54.  
  55. <link rel="stylesheet" href="css/style.css">
  56. <script>
  57. function validate_required(field,alerttxt)
  58. {
  59. with (field)
  60. {
  61. if (value==null||value=="")
  62. {
  63. alert(alerttxt);return false;
  64. }
  65. else
  66. {
  67. return true;
  68. }
  69. }
  70. }
  71.  
  72. function validate_form(thisform)
  73. {
  74. with (thisform)
  75. {
  76. if (validate_required(username,"Username must be filled out!")==false)
  77. { user.focus(); return false;}
  78. else if (validate_required(password,"Password must be filled out!")==false)
  79. { pass.focus(); return false;}
  80. }
  81. }
  82. </script>
  83.  
  84. </head>
  85.  
  86. <body>
  87. <div class="header">
  88. <div class="wrapper">
  89. <div class="container">
  90. <img src="Logo_KUET.svg" alt="Northern Lights" width="45%" height="40%">
  91. <h1><p class="thicker">KUET Alumni</p><h1>
  92.  
  93. <form method="post" action="log.php" onSubmit="return validate_form(this)" method="post" >
  94. <td><input type="text" name="username" placeholder="Enter Username" class="textInput" value="<?php echo $temp ?>"/></td>
  95. <td><input type="password" name="password" placeholder="Enter Password" class="textInput" value="<?php echo $temp1 ?>"/></td>
  96. <button type="submit" name="login_btn" id="login-button">Log In</button>
  97. </form>
  98. </div>
  99.  
  100. <ul class="bg-bubbles">
  101. <li></li>
  102. <li></li>
  103. <li></li>
  104. <li></li>
  105. <li></li>
  106. <li></li>
  107. <li></li>
  108. <li></li>
  109. <li></li>
  110. <li></li>
  111. </ul>
  112. </div>
  113. </div>
  114.  
  115. <?php
  116. if(isset($_SESSION['message'])){
  117. echo "<div style=color:red>".$_SESSION['message']."</div>";
  118. unset($_SESSION['message']);
  119. }
  120. ?>
  121.  
  122. </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement