Forum Moderators: coopster

Message Too Old, No Replies

Password protection

         

wendystewart80

11:55 am on Oct 31, 2005 (gmt 0)

10+ Year Member



Hi there,
I am trying to password protect my website.
I have the following code, which works, but the error message comes up saying:
Unidentified index - password.
Meaning the first line that 'password' appears on.
What do I need to do to get rid of this error message?
[php]
?php
if($_POST['password']) {
if($_POST['password'] == 'MYPASSWORD') {
?>
Put your page's contents here.
<?php
} else {
?>
Incorrect password - please try again.
<?php
}
} else {
?>
<form method='post' action='login.php'>
<p>
<input type="text" name="password" size=25 maxlength=25>
Password</p>
<p>
<input type="Submit" name="Submit" value="Search">
<input type="reset" name="Clear" value="Clear">
</p>
</form>
<?php
}
?> [/php]

Twisted Mind

1:35 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



maybe becouse you have [post]password tag on top of your page? it seems like you just dont want to give entrance to your page with the password so i would put the tag on top of an other target's page

coopster

6:39 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That error means that the index has not been set yet, in this case since the first time you load the page it has not been POSTed, there will be no 'password' index in the $_POST superglobal array. You should check and see if it isset() [php.net] yet.

gsnider

8:45 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



You have your php.ini file to warn if you don't set a variable before using it...

Find this line in your php.ini file:
error_reporting = E_ALL

Set that line to look like this:
error_reporting = E_ALL & ~E_NOTICE

That removes notices like the Unidentified one.

You could also try doing:


<?php
$passvar = $_POST['password'];

if($passvar!= "") {
if($passvar == 'MYPASSWORD') {
?>
Put your page's contents here.
<?php
} else {
?>
Incorrect password - please try again.
<?php
}
} else {
?>
<form method="post" action="login.php">
<p>
<input type="text" name="password" size=25 maxlength=25>
Password</p>
<p>
<input type="submit" name="submit" value="Search">
<input type="reset" name="clear" value="Clear">
</p>
</form>
<?php
}
?>