Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

php Password protect a page

Sun Oct 26, 2008 6:09 pm

Password protection for a single page. Visitors are required to enter a password and username into a login form to view the page content.

Code:
<?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

}

?>




Re: php Password protect a page

Sat Apr 14, 2012 7:04 pm

Notice: Undefined index: txtUsername in D:\xampp\htdocs\index.php on line 13

Post a reply
  Related Posts  to : php Password protect a page
 Protect page using password in PHP     -  
 How to protect your software     -  
 Image Scroller-scrollbar-LINE_UP,LINE_DOWN-PAGE-UP-PAGE-DOWN     -  
 generate password using php     -  
 how to encrypt password in jsp     -  
 simple password Strength checker     -  
 Input username and password in JAVA     -  
 Password Security Manager Access File Java     -  
 AJAX Login Code getting username and password dynamically .     -  
 Mile200: Removing Username, Password & Login from Header     -