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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.