Guest User

Untitled

a guest
Aug 12th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. Simple PHP Multi User login, different pages depending on user - what's wrong here?
  2. <?php
  3. session_start();
  4. $data=array("user1"=>array("url"=>"file1.php","password"=>"pass1"),
  5. "user2"=>array("url"=>"file2.php","password"=>"pass2"));
  6.  
  7. if(isset($_POST['username']) && isset($_POST['password'])) {
  8. if($data[$_POST['username']]['password'] == $_POST['password']) {
  9. $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
  10. header('Location: ' . $data[$_POST['username']]['url']);
  11.  
  12. login('<p class="alert">Incorrect username or password.</p> ');
  13. }
  14. } else {
  15. login();
  16. }
  17. ?><?php
  18. function login($response='Please enter your username and password.') {
  19. ?>
  20.  
  21. <p><?=$response?></p>
  22. <form action="" method="post">
  23. <table width="400" border="0" cellspacing="0" cellpadding="4">
  24. <tr>
  25. <td width="90"><label class="loginform" for="username">Username:</label></td>
  26. <td width="294"><input name="username" type="text" /></td>
  27. </tr>
  28. <tr>
  29. <td><label for="password">Password:</label></td>
  30. <td><input name="password" type="password"></td>
  31. </tr>
  32. <tr>
  33. <td>&nbsp;</td>
  34. <td><input type="submit" value="Login" /></td>
  35. </tr>
  36. </table>
  37. </form>
  38. <?php } ?>
  39.  
  40. <?php } ?>
  41.  
  42. if(isset($_POST['username']) && isset($_POST['password']))
  43. {
  44. if($data[$_POST['username']]['password'] == $_POST['password'])
  45. {
  46. $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
  47. header('Location: ' . $data[$_POST['username']]['url']);
  48.  
  49. login('<p class="alert">Incorrect username or password.</p> ');
  50. }
  51. } else {
  52. login();
  53. }
  54.  
  55. if(isset($_POST['username']) && isset($_POST['password']))
  56. {
  57. if($data[$_POST['username']]['password'] == $_POST['password'])
  58. {
  59. $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
  60. header('Location: ' . $data[$_POST['username']]['url']);
  61. exit();
  62. }
  63. else
  64. {
  65. login('<p class="alert">Incorrect username or password.</p> ');
  66. }
  67. } else {
  68. login();
  69. }
  70.  
  71. $warning = '';
  72.  
  73. if(isset($_POST['username']) && isset($_POST['password']))
  74. {
  75. if($data[$_POST['username']]['password'] == $_POST['password'])
  76. {
  77. $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
  78. header('Location: ' . $data[$_POST['username']]['url']);
  79. exit();
  80. }
  81. else
  82. {
  83. $warning = '<p class="alert">Incorrect username or password.</p> ';
  84. }
  85. }
  86.  
  87. login($warning);
  88.  
  89. if(isset($_POST['username']) && isset($_POST['password'])) {
  90. if($data[$_POST['username']]['password'] == $_POST['password']) {
  91. $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
  92. header('Location: ' . $data[$_POST['username']]['url']);
  93.  
  94. login('<p class="alert">Incorrect username or password.</p> ');
  95.  
  96. }
  97. } else {
  98. login();
  99. }
  100.  
  101. if(isset($_POST['username']) && isset($_POST['password'])) {
  102. if($data[$_POST['username']]['password'] == $_POST['password']) {
  103. $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
  104. header('Location: ' . $data[$_POST['username']]['url']);
  105.  
  106. } else {
  107. login('<p class="alert">Incorrect username or password.</p> ');
  108. }
  109. } else {
  110. login();
  111. }
Add Comment
Please, Sign In to add comment