# Password Protected Redirect Directories

**URL:** <https://forum.kirupa.com/t/password-protected-redirect-directories/167246>\
**Category:** programming\
**Created:** [October 26, 2005, 4:12pm UTC](https://forum.kirupa.com/t/password-protected-redirect-directories/167246 "2005-10-26T16:12:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wyclef](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@wyclef](https://forum.kirupa.com/u/wyclef)\
**Post date:** [October 26, 2005, 4:12pm UTC](https://forum.kirupa.com/t/password-protected-redirect-directories/167246/1 "2005-10-26T16:12:46Z")

</div>

Would there be a way to modify this so I could use it with multiple usernames and passwords so I could redirect a user to a specified directory that you could only see if you had logged in on a master page first.

```php

<?php

// Define your username and password
$username = "someuser";
$password = "somepassword";

if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {

?>

<h1>Login</h1>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <p><label for="txtUsername">Username:</label>
    <br /><input type="text" title="Enter your Username" name="txtUsername" /></p>

    <p><label for="txtpassword">Password:</label>
    <br /><input type="password" title="Enter your password" name="txtPassword" /></p>

    <p><input type="submit" name="Submit" value="Login" /></p>

</form>

<?php

}
else {

?>

<p>This is the protected page. Your private content goes here.</p>

<?php

}

?> 

```

If I change the bottom to

```php

<?php

}
else {

header( 'Location: http://www.test.com/test' );

}

?> 

```

I can redirect the user but how can I do this for multiple users and how can I make sure they have to be logged in so they can’t just go to the URL in the first place?
