Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. --------------------------- index.php Code --------------------------------
  2.  
  3. <?php
  4. session_start();
  5. if (isset($_SESSION['logged']))
  6. {
  7. include "indexl.inc.php";
  8. }
  9. // Not Logged.
  10. else
  11. {
  12. include "indexnl.inc.php";
  13. }
  14. ?>
  15. ----------------------------- indexl.inc.php ----------------------------------
  16.  
  17. <?php
  18. if (isset($_SESSION['logged']))
  19. {
  20. $username = $_SESSION['logged'];
  21. include "sql.php";
  22. $query = mysql_query("SELECT * FROM `users` WHERE username='$username'");
  23. $numrow = mysql_num_rows($query);
  24. if ($numrow == 0)
  25. {
  26. header("Location: index.php");
  27. }
  28. else
  29. {
  30. while ($row = mysql_fetch_array($query))
  31. {
  32. $name = $row['name'];
  33. $lastname = $row['lastname'];
  34. }
  35. }
  36. }
  37. else
  38. {
  39. header("Location: index.php");
  40. }
  41. ?>
  42. <html>
  43. <head>
  44.  
  45. <title></title>
  46. </head>
  47. <body>
  48.  
  49. <?php
  50. echo "Hello, $name $lastname<br />";
  51. echo " <a href=\"logout.php\">Logout</a>";
  52. ?>
  53. <p>
  54. <a href="index.php">Home</a> |
  55. <a href="profile.php">Profile</a>
  56. </p>
  57. </body>
  58. </html>
  59.  
  60. -------------------------------- indexnl.inc.php ---------------------------
  61. <?php
  62. if (isset($_SESSION['logged']))
  63. {
  64. header("Location: index.php");
  65. }
  66. ?>
  67. <html>
  68. <head>
  69. <title></title>
  70. </head>
  71. <body>
  72. <form method="POST" action="">
  73. Username : <input type="text" name="username" />
  74. Password : <input type="password" name="password" />
  75. <input type="submit" name="submit" value="Login" />
  76. </form>
  77. <a href="register.php">Not a Member yet?</a>
  78. <?php
  79. if (isset($_POST['submit']))
  80. {
  81. if (empty($_POST['username']) || empty($_POST['password']))
  82. {
  83. echo "Username Or/And Password is empty.";
  84. }
  85. else
  86. {
  87. include "sql.php";
  88. $username = mysql_real_escape_string(ucwords(strtolower($_POST['username'])));
  89. $password = md5(strtolower($_POST['password']));
  90. $query = mysql_query("SELECT * FROM `users` WHERE username='$username'");
  91. $numrow = mysql_num_rows($query);
  92. if ($numrow == 0)
  93. {
  94. echo "Username Or/And Password is wrong.";
  95. }
  96. else
  97. {
  98. while ($row = mysql_fetch_array($query))
  99. {
  100. $rowusername = $row['username'];
  101. $rowpassword = $row['password'];
  102. }
  103. if ($username == $rowusername)
  104. {
  105. if ($password == $rowpassword)
  106. {
  107. // ---- Logged in ---- \\
  108. $_SESSION['logged'] = $username;
  109. header("Location: index.php");
  110. }
  111. else
  112. {
  113. echo "Username Or/And Password is wrong.";
  114. }
  115. }
  116. else
  117. {
  118. echo "Username Or/And Password is wrong.";
  119. }
  120. }
  121. }
  122.  
  123. }
  124.  
  125.  
  126. ?>
  127.  
  128. </body>
  129. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement