[UPHPU] PHP Password Protect

Jeremy Burgess jeremy at edgecast.net
Mon Dec 11 13:48:33 MST 2006


Webot Graphics wrote:

> I want to be able to password protect a download. The page that was  
> built for the company has a pre formatted page which contains  
> JavaScript (and looks ugly to me) but they want to be able to  
> password protect a downloadable catalog.
>
> I can't get the formatting to appear in this page. I am still new to  
> PHP so I am not sure if I am even on the right tract.
>
> here is the link to this page. www.westernbotanicals.com/en/ 
> whlcatalog.php. This is what a regular page looks like.  
> www.westernbotanicals.com/en/front.html
>
> <?php
> // Define your username and password
> $username = "hello";
> $password = "world";
> if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] !=  
> $password) {
> ?>
> <HTML> ... </HTML>
> <?php
> } else {
> ?>
> <p>This is the protected page. Your private content goes here.</p>
> <?php
> }
> ?>

You are on 'a' right track. There are more sophisticated and secure ways 
of doing this, but your way can work. It looks like you just need to fix 
the if statement.

from this:
$_POST['txtUsername'] != $username || $_POST['txtPassword'] !=  $password)
to this:
$_POST['txtUsername'] == $username && $_POST['txtPassword'] ==  $password)

that way you are only showing the page when BOTH $username and $password 
(hence the '&&') are equal to (hence the '==') txtUsername and 
txtPassword respectively.

-Jeremy


More information about the UPHPU mailing list