Advertisement
Guest User

Untitled

a guest
Mar 29th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <!-- title of the web page-->
  5. <title>Login</title>
  6.  
  7.  
  8. <!--webpage metatags -->
  9. <meta charset="utf-8" />
  10.  
  11. <!--specific web page meta tags-->
  12.  
  13.  
  14. <!--CSS links-->
  15. <link rel="stylesheet" rel="text/css" href="style.css" />
  16.  
  17. </head>
  18. <body>
  19.  
  20. <!--register users-->
  21.  
  22. <form name="register" method="post"
  23. action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" >
  24.  
  25.  
  26. <strong> Login</strong><br /><br />
  27.  
  28. User name:
  29. <input type="text" name="username"><br /><br />
  30.  
  31.  
  32. Password:
  33. <input type="text" name="password"><br /><br />
  34.  
  35. <input type = "submit" value ="Register" />
  36.  
  37. </form>
  38.  
  39. <?php
  40. // statistics
  41. session_start(); // start of the session
  42. // the first time you visit
  43. $fileLocation="stats/login.txt";
  44. if(!isset($_SESSION['counter'])) {
  45. // open the file
  46. $file = fopen($fileLocation, "r");
  47. if(!$file){
  48. echo "Could not open the file" ;
  49. }
  50. else {
  51. // read the file and get the counter
  52. $counter = ( int ) fread ($file,20) ;
  53. fclose ($file);
  54. $counter++ ;
  55. echo" <p> Visitor Count: ". $counter . " </p> " ;
  56. $file = fopen($fileLocation, "w" ) ;
  57. fwrite($file,$counter) ;
  58. fclose ($file) ;
  59. $_SESSION['counter'] = $counter;
  60. }
  61.  
  62. } else { // It's not the first time, do not update the counter but show the total hits stored in session
  63. $counter = $_SESSION['counter'];
  64. echo" <p> Visitor Count: ". $counter . " </p> " ;
  65. }
  66.  
  67. //validate registration form
  68.  
  69. if((empty ($_POST['username'])) OR (empty($_POST['password'])))
  70. {
  71. //if the values are empty -
  72. echo "<br/> Please fill in all the above inputs";
  73.  
  74.  
  75. }else{
  76. echo "<br> Process Validation";
  77. //if the inputs has values
  78.  
  79. //store the data into local variables
  80.  
  81. $Uname = $_POST['username'];
  82. $Pname = $_POST['password'];
  83. $Check=true;
  84.  
  85.  
  86.  
  87.  
  88.  
  89. //validate Username as email address
  90.  
  91. //validate password - more then 5 char
  92. if (strlen($Pname) <5 )
  93. {
  94. echo "<br> Username or password is incorrect";
  95. //open error_log.txt as append
  96. $File="error_log.txt";
  97. $OpenFile = fopen($File, 'a');
  98. $ip = $_SERVER['REMOTE_ADDR'];
  99. $time = date("h:i:sa");
  100. $date = date("d/m/y");
  101. $error = 'incorrect name entered';
  102. $stringData = "$ip, $time, $date, $error\n";
  103. fwrite($OpenFile, $stringData);
  104. fclose($OpenFile);
  105. $Check=false;
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //if all the validation are true then prepare
  115. //to store to online database table
  116. if ($Check == true)
  117. {
  118. echo "<br>Checking.....</br>";
  119.  
  120. require_once('db.php');//connect the database
  121.  
  122. $SQL = "SELECT * FROM user WHERE username = '$Uname' and password= '$Pname'";
  123.  
  124. $result = $conn->query($SQL); //execyte the SQL query. Store the data in $result as an array.
  125.  
  126. if ($result->num_rows >0)
  127. {
  128. //the users information is available in the database.
  129. echo "<br> Login Successful";
  130. echo "<br><br> re-direct to members page";
  131. header ( 'refresh:5; url=member.php?id='.$Uname);// re-directs to the member page after 5 sec delay.
  132. }
  133.  
  134.  
  135. else {
  136. // The users information has not been found.
  137. echo "<br> Username or Password incorrect";
  138.  
  139.  
  140. }
  141.  
  142. }
  143.  
  144.  
  145.  
  146. }
  147. ?>
  148. </body>
  149. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement