PHP >> Password Protected Pages

This is your entire page! You just copy and past this on whatever page you want to be password protected, naming it whatever you want. Though, remember, the file name has to end in .php.

Copy and past this entire code:

<?php
include(“header.php”);

// Define your username and password
$username = “username”;
$password = “password”;

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

?>

To log in, fill out this form:
<p><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></p>

<?php

}
else {

?>

THIS IS THE PASSWORD PROTECTED PAGE THAT THE USERNAME AND PASSWORD WILL LEAD TO ONCE ENTERED AND CORRECT.

<?php

}
include(“footer.php”);
?>

You add your username and password by changing these variables to whatever you want them to be:

$username = “username”;
$password = “password”;

Also, before the actual sign in form, you are welcome to add anything that you want, as well as after it.


Page Views: 142 views

Leave a Reply

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

CommentLuv badge