Jump to content

Password protect a certain part of the page


El Estrago

Recommended Posts

I'm looking for a (good) php script which password protects a certain part of the page.

This is what I've got:

<?php

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

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

?>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

Username: <input type="text" name="txtUsername" />
Password: <input type="password" name="txtPassword" />
<input type="submit" value="Submit" />

</form>

//else bit

<?php

}

else {

?>

<p> passworded bit </p>

<?php

}

?>

 

Problem: it doesn't work.  :(

I think it has got something to do with the if/else-part.

Replace the if statement with:

 

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

 

You have to check if the variables are even set in the first place, and also, your pipe character seems funny...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.