Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Simple PHP Multi User login, different pages depending on user - what's wrong here?
- <?php
- session_start();
- $data=array("user1"=>array("url"=>"file1.php","password"=>"pass1"),
- "user2"=>array("url"=>"file2.php","password"=>"pass2"));
- if(isset($_POST['username']) && isset($_POST['password'])) {
- if($data[$_POST['username']]['password'] == $_POST['password']) {
- $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
- header('Location: ' . $data[$_POST['username']]['url']);
- login('<p class="alert">Incorrect username or password.</p> ');
- }
- } else {
- login();
- }
- ?><?php
- function login($response='Please enter your username and password.') {
- ?>
- <p><?=$response?></p>
- <form action="" method="post">
- <table width="400" border="0" cellspacing="0" cellpadding="4">
- <tr>
- <td width="90"><label class="loginform" for="username">Username:</label></td>
- <td width="294"><input name="username" type="text" /></td>
- </tr>
- <tr>
- <td><label for="password">Password:</label></td>
- <td><input name="password" type="password"></td>
- </tr>
- <tr>
- <td> </td>
- <td><input type="submit" value="Login" /></td>
- </tr>
- </table>
- </form>
- <?php } ?>
- <?php } ?>
- if(isset($_POST['username']) && isset($_POST['password']))
- {
- if($data[$_POST['username']]['password'] == $_POST['password'])
- {
- $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
- header('Location: ' . $data[$_POST['username']]['url']);
- login('<p class="alert">Incorrect username or password.</p> ');
- }
- } else {
- login();
- }
- if(isset($_POST['username']) && isset($_POST['password']))
- {
- if($data[$_POST['username']]['password'] == $_POST['password'])
- {
- $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
- header('Location: ' . $data[$_POST['username']]['url']);
- exit();
- }
- else
- {
- login('<p class="alert">Incorrect username or password.</p> ');
- }
- } else {
- login();
- }
- $warning = '';
- if(isset($_POST['username']) && isset($_POST['password']))
- {
- if($data[$_POST['username']]['password'] == $_POST['password'])
- {
- $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
- header('Location: ' . $data[$_POST['username']]['url']);
- exit();
- }
- else
- {
- $warning = '<p class="alert">Incorrect username or password.</p> ';
- }
- }
- login($warning);
- if(isset($_POST['username']) && isset($_POST['password'])) {
- if($data[$_POST['username']]['password'] == $_POST['password']) {
- $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
- header('Location: ' . $data[$_POST['username']]['url']);
- login('<p class="alert">Incorrect username or password.</p> ');
- }
- } else {
- login();
- }
- if(isset($_POST['username']) && isset($_POST['password'])) {
- if($data[$_POST['username']]['password'] == $_POST['password']) {
- $_SESSION['username'] = $_POST['username'] . " " . $_POST['password'];
- header('Location: ' . $data[$_POST['username']]['url']);
- } else {
- login('<p class="alert">Incorrect username or password.</p> ');
- }
- } else {
- login();
- }
Add Comment
Please, Sign In to add comment