Worth2Read
Home

Forum

PHP Tutorials
Blogs
Children
Article Directory

Contact Us

Disclaimer
Reliable $1 Web Hosting by 3iX
 

If you have any doubts with your PHP code please discuss it in the PHP Forum

Password Protect a single web page for a single user

The following code can be used to password protect a webpage for a single user. The 'username' and 'password' needs to be changed accordingly.

<?php

$username = "username";
$password = "password";

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

?>

<h1>Login</h1>

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

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

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

</form>

<?php

}
else {

?>

<p>Enter the contents of the page here.</p>
<?php
}
?>

You can see a demo of this code at http://www.worth2read.org/test/password_protect3.php


Copyright © 2008 www.worth2read.org. All rights Reserved. Use of this Site is subject to our Privacy Statement

Untitled Document