login.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. session_start(); // start session.
  3. include('configuration');
  4. if($_SESSION['slogged'] != ''){
  5. include('logo.html');
  6. include('menulist.html');
  7. echo "<br><div align=\"center\">Already logged in as ".$_SESSION['susername']."...</div>";
  8. exit();
  9. }
  10. if(!isset($_POST['submit'])) {
  11. include('logo.html');
  12. include('menulist.html');
  13. loginhtml("Members only. Please login to access.");
  14. exit();
  15. }
  16. // get username and password
  17. $username = $_POST['username'];
  18. $password = $_POST['password'];
  19. // register username and logged as session variables.
  20. session_register("susername");
  21. session_register("slogged");
  22. //set session variables
  23. $_SESSION["susername"] = $username;
  24. $_SESSION["slogged"] = false;
  25. // open database file
  26. $handle = sqlite3_open($db) or die("Could not open database");
  27. // query string
  28. $query = "SELECT * FROM login where username=\"$username\"";
  29. // execute query
  30. $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
  31. // if rows exist
  32. if (($row = sqlite3_fetch_array($result)) != '') {
  33. if(md5($password) == $row["password"])
  34. $valid_user = 1;
  35. }
  36. else {
  37. $valid_user = 0;
  38. }
  39. //if not valid user
  40. if (!($valid_user)) {
  41. // Unset session variables.
  42. session_unset();
  43. include('logo.html');
  44. include('menulist.html');
  45. loginhtml("Incorrect login information, please try again. You must login to access.");
  46. exit();
  47. }
  48. //if valid user
  49. else {
  50. $referer = $_GET['referer'];
  51. $_SESSION["slogged"] = true;
  52. if($referer != '') {
  53. header('Location: '.$referer);
  54. exit();
  55. }
  56. include('logo.html');
  57. include('menulist.html');
  58. echo "<br><div align=\"center\">Logged in sucessfully...<//div><//body><//html>";
  59. }
  60. function loginhtml($info)
  61. {
  62. ?>
  63. <form action="<?=$PHP_SELF.$referer?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
  64. <p align="center"><?=$info?></p>
  65. <table align="center" border="0">
  66. <tr>
  67. <th>
  68. Username:
  69. </th>
  70. <th>
  71. <input type="text" name="username">
  72. </th>
  73. </tr>
  74. <tr>
  75. <th>
  76. Password:
  77. </th>
  78. <th>
  79. <input type="password" name="password">
  80. </th>
  81. </tr>
  82. <tr>
  83. <th colspan="2" align="right">
  84. <input type="submit" name="submit" value="Login">
  85. </form>
  86. </th>
  87. </tr>
  88. </table><hr>
  89. </body>
  90. </html>
  91. <?php
  92. }
  93. ?>