Page 1 of 1
[SOLVED][56K WARN]Simple Password Code
Posted: Wed Nov 30, 2005 6:23 pm
by nickman013
Ok, I have created my own password script, it is similar to others, but I have one small problem.
When ever I go to the page It looks like this

It already shows, THE PASSWORD YOU ENTERED IS INCORRECT before I enter in a incorrect password, I dont want that. I want it to look like,
But I want it to say THE PASSWORD YOU ENTERED IS INCORRECT after they enter an incorrect password.
But when I do enter a correct password the page looks like this,

I want the form to go away.
My script is
Code: Select all
<html>
<title>Password...</title><center><font size=8 color=black>
<form method=post action=Password.php3>
Password: <input type=password name=pw><br>
<input type=submit>
</font><p><p><p></html>
<?
$content = "<html><font size=7>
<p><p><p><a href=url>Page1</a><br>
<a href=url>page2</a><br>
<a href=url>Stats</a><br>
</font></html>";
$wrong = "<html><font size=5 color=red><b><u>THE PASSWORD YOU ENTERED IS IN CORRECT</u></b></font></html>";
if ("password_here" == $pw) {echo $content;} else {echo $wrong;}
?>
Posted: Wed Nov 30, 2005 6:26 pm
by John Cartwright
If you havn't noticed, that file does not exist.
Posted: Wed Nov 30, 2005 6:38 pm
by nickman013
yeah i submitted it on accident and you replied as i was editing it
Posted: Wed Nov 30, 2005 6:50 pm
by John Cartwright
Firstly, your script requires register global to be ON.. which it definantly 400% should not be. Ask your host to disable it if it is. Why?
Read the manual
1) you must check if the form has been submitted or not.. use $_POST to access the form variables.
2) You are also using tags like <font> or <center> which are deprecated and will not function as expected on multiple browsers/platforms. Instead use a inline style
3) You are opening your <html> tag twice. No No.
Code: Select all
?>
<html>
<head>
<title>Password...</title>
</head>
<body>
<div style="font-size: 8px; color: black">
<form method=post action=Password.php3>
Password: <input type=password name=pw><br />
<input type=submit>
</form>
<?
//check if something was entered into field
if (!empty($_POST['pw'])) {
if ($_POST['pw'] == 'password_here') {
//put links or whatever here since he has validated
}
else {
//show error message here
}
}
?>
</div>
</body>
</html>
Wow I just noticed you are using php3... absolutely insanely old version of php!! we are 2 versions ahead of you!! UPGRADE!!
Posted: Wed Nov 30, 2005 7:07 pm
by nickman013
ook thanks, now im getting a parse error
my script..
Code: Select all
<html>
<head>
<title>Password...</title>
</head>
<body>
<div style="font-size: 14px; color: black">
<form method=post action=Password.php3>
Password: <input type=password name=pw><br />
<input type=submit>
</form>
</div>
</html>
<?
//check if something was entered into field
if(!empty($_POST['pw'])) {
if($_POST['pw'] == 'password') {ok}
else {wrong}
}
?>
The error...
Parse error: parse error in /web/u54/www22882/www/test3.php3 on line 16
Line 16...
if($_POST['pw'] == 'password') {ok}
The form does show up above the parse error.
Posted: Wed Nov 30, 2005 7:15 pm
by John Cartwright
Code: Select all
if(!empty($_POST['pw'])) {
if($_POST['pw'] == 'password') {
echo $ok; //not sure what you wanted to do here
}
else {
echo $wrong;
}
}
You need $ infront of your variable names.. assuming they are variable names
and believe me, learn to indent properly.. makes a world of difference
Posted: Wed Nov 30, 2005 7:22 pm
by nickman013
k,
when it was indented i had all these I looking characters...
but otherwise now when i go to the page i dont get a parse error, i get the form if i enter a incorrect password the page refreshes, nothing changes, same thing when i type in the correct password.
updated script
Code: Select all
<html>
<head>
<title>Password...</title>
</head>
<body>
<div style="font-size: 14px; color: black">
<form method=post action=test3.php3>
Password: <input type=password name=pw><br />
<input type=submit>
</form>
</div>
</html>
<?
//check if something was entered into field
if(!empty($_POST['pw'])) {
if($_POST['pw'] == 'password') {
echo $ok;}
else {
echo $wrong;}
}
?>
Posted: Wed Nov 30, 2005 7:25 pm
by John Cartwright
$ok and $wrong are never set...
Posted: Wed Nov 30, 2005 7:27 pm
by nickman013
i know, i added them just now and same thing
updated script
Code: Select all
<html>
<head>
<title>Password...</title>
</head>
<body>
<div style="font-size: 14px; color: black">
<form method=post action=test3.php3>
Password: <input type=password name=pw><br />
<input type=submit>
</form>
</div>
</html>
<?
$content = "<html><font size=7>
<p><p><p><a href=http://www.site.com/nvideos.php3?page=muot>Muot Page</a><br>
<a href=http://www.site.com/nvideos.php3?page=gotti>Gotti Page</a><br>
<a href=http://r.net/link/a/?a=23f3645734f870a7&b=nickman013>Stats</a><br>
</font></html>";
$wrong = "<html><font size=5 color=red><b><u>THE PASSWORD YOU ENTERED IS IN CORRECT</u></b></font></html>";
//check if something was entered into field
if(!empty($_POST['pw'])) {
if($_POST['pw'] == 'password') {
echo $content;}
else {
echo $wrong;}
}
?>
Posted: Wed Nov 30, 2005 7:30 pm
by John Cartwright
Ah sorry I forgot you are using php3... change $_POST to $HTTP_POST_VARS
Posted: Wed Nov 30, 2005 7:36 pm
by nickman013
cool, it works. but now when i enter the correct password the form stays, is there a way to get rid of it?
Posted: Wed Nov 30, 2005 7:40 pm
by John Cartwright
I figured you'd be asking that...
I would probably use a wrap your form into a function so you may call upon it in different instances.
Code: Select all
<html>
<head>
<title>Password...</title>
</head>
<body>
<div style="font-size: 14px; color: black">
<?
function showForm() {
echo '<form method=post action=test3.php3>
Password: <input type=password name=pw><br />
<input type=submit>
</form>';
}
$content = "<html><font size=7>
<p><p><p><a href=http://www.site.com/nvideos.php3?page=muot>Muot Page</a><br>
<a href=http://www.site.com/nvideos.php3?page=gotti>Gotti Page</a><br>
<a href=http://r.net/link/a/?a=23f3645734f870a7&b=nickman013>Stats</a><br>
</font></html>";
$wrong = "<html><font size=5 color=red><b><u>THE PASSWORD YOU ENTERED IS IN CORRECT</u></b></font></html>";
//check if something was entered into field
if(!empty($HTTP_POST_VARS['pw'])) {
if($HTTP_POST_VARS['pw'] == 'password') {
echo $content;}
else {
echo $wrong;
showForm();
}
else {
showForm();
}
}
?>
</div>
Posted: Wed Nov 30, 2005 8:03 pm
by nickman013
Script:
Code: Select all
<html>
<head>
<title>Password...</title>
</head>
<body>
<div style="font-size: 14px; color: black">
<?
function showForm() {
echo "<form method=post action=test3.php3>
Password: <input type=password name=pw><br />
<input type=submit>
</form>";
}
$content = "<html><font size=7>
<p><p><p><a href=http://www.site.com/nvideos.php3?page=muot>Muot Page</a><br>
<a href=http://www.site.com/nvideos.php3?page=gotti>Gotti Page</a><br>
<a href=http://r.net/link/a/?a=23f3645734f870a7&b=nickman013>Stats</a><br>
</font></html>";
$wrong = "<html><font size=5 color=red><b><u>THE PASSWORD YOU ENTERED IS IN CORRECT</u></b></font></html>";
//check if something was entered into field
if(!empty($HTTP_POST_VARS['pw'])) {
if($HTTP_POST_VARS['pw'] == 'password') {
echo $content;}
else {
echo $wrong;
showForm();
}
else {
showForm();
}
}
?>
</div>
</html>
Parse Error:
Parse error: parse error in /web/u54/www22882/www/test3.php3 on line 30
Line 30:
else {
Posted: Wed Nov 30, 2005 8:12 pm
by John Cartwright
This is why indentation helps...
Code: Select all
if(!empty($HTTP_POST_VARS['pw'])) {
if($HTTP_POST_VARS['pw'] == 'password') {
echo $content;
}
else {
echo $wrong;
showForm();
}
}
else {
showForm();
}
Posted: Wed Nov 30, 2005 8:28 pm
by nickman013