Jump to content
xisto Community
tricky77puzzle

A Simple Password Page I cant make one

Recommended Posts

I'm trying to make a simple password page for one of my PHP experiments. Every time I try to post a password, however, it returns an error that the connection was "closed by the server".

The entire code is only 3 pages.

password.php:



if $_POST['user'] !== $rightuser
{ if $rightuser == ''
{
?>The username is incorrect. It should be blank.<?php ;
}
else
{
?>The username is incorrect. It should be .<?php ;
}
}
else
{ if $_POST['pass'] !== $rightpass
{ if $rightpass == ''
{
?>The password is incorrect. It should be blank.<?php ;
}
else
{
?>The password is incorrect. It should be<?php echo $rightpass;
}
}
else
{ ?>The password is correct.'; }<?php
}
?> linenums:0'><?php$rightuser = "";$rightpass = "";include ('getpassword.php');if $_POST['user'] !== $rightuser { if $rightuser == '' { ?>The username is incorrect. It should be blank.<?php ; }else { ?>The username is incorrect. It should be .<?php ; }}else{ if $_POST['pass'] !== $rightpass { if $rightpass == '' { ?>The password is incorrect. It should be blank.<?php ; }else { ?>The password is incorrect. It should be<?php echo $rightpass; }}else{ ?>The password is correct.'; }<?php}?>
getpassword.php:

<?php $rightuser = "";$rightpass = "1234567890";?>

password.html:

<html><head></head><body><form action="password.php"><p>Username: <input type="text" name="user" /></p><p>Password: <input type="text" name="pass" /></p><p><input type="submit" value="Submit" /></p></form></body>

What am I doing wrong? Help is greatly appreciated...

Share this post


Link to post
Share on other sites

password.php:



if $_POST['user'] !== $rightuser
{ if $rightuser == ''
{
?>The username is incorrect. It should be blank.<?php ;
}
else
{
?>The username is incorrect. It should be .<?php ;
}
}
else
{ if $_POST['pass'] !== $rightpass
{ if $rightpass == ''
{
?>The password is incorrect. It should be blank.<?php ;
}
else
{
?>The password is incorrect. It should be<?php echo $rightpass;
}
}
else
{ ?>The password is correct.'; }<?php
}
?> linenums:0'><?php$rightuser = "";$rightpass = "";include ('getpassword.php');if $_POST['user'] !== $rightuser { if $rightuser == '' { ?>The username is incorrect. It should be blank.<?php ; }else { ?>The username is incorrect. It should be .<?php ; }}else{ if $_POST['pass'] !== $rightpass { if $rightpass == '' { ?>The password is incorrect. It should be blank.<?php ; }else { ?>The password is incorrect. It should be<?php echo $rightpass; }}else{ ?>The password is correct.'; }<?php}?>
getpassword.php:


password.html:

<html> <head> </head> <body>  <form action="password.php"> <p>Username: <input type="text" name="user" /></p> <p>Password: <input type="text" name="pass" /></p> <p><input type="submit" value="Submit" /></p> </form>  </body>

Alright, you have errors in these two pieces of code.

In the first, your if statements aren't typed right. Instead of "!==" it needs to be "!=".

An if statement also goes in the format if(*argument*){do something}else{do something}. For example

if($password == 'hi'){.. wrong password..}else{	if($password != 'hi') //does the same as an else just showing the not equal operator	{		right password	}}

The next error comes in your form, but it's an easy mistake. Just fix the form tag to " <form action='password.php' method='post'>".
This will post your data to your password.php file so that the php code can retrieve the data.

Hope this helps

Share this post


Link to post
Share on other sites

A single page will do that for you...

<?php$rightuser = "me";$rightpass = "123";if ( isset($_POST['user']) ) { 		if ( $rightpass == $_POST['pass'] ) {				 echo '<p style=" color:green; ">Good Password</p>';		 }		else {   /* password condition else */				echo '<p style=" color:red; ">Bad Password</p>';				}   /* password condition end */		if ( $rightuser == $_POST['user'] ) {				 echo '<p style=" color:green; ">Good Username</p>';		 }		else {   /* user condition else */				echo '<p style=" color:red; ">Bad Username</p>';							 }   /* user condition end */}	 /* main condition end */?><html><head></head><body><form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST"><p>Username: <input type="text" name="user" value="<?php if ( isset($_POST['user']) ) { echo $_POST['user']; } ?>" /></p><p>Password: <input type="text" name="pass" value="<?php if ( isset($_POST['pass']) ) { echo $_POST['pass']; } ?>" /></p><p><input type="submit" value="Submit" /></p></form></body></html>
Change the password and user as you need to, or add them into another file and include() them like your example code and delete them from this file. That might be better since it would save you having to edit the file containing the code itself. Less chance of messing it up.

Also, there is no Data checking in this script and you should at least add an function to convert the html entities to avoid someone goofing around with the page. I'll leave the level of data-checking to you. PM me if you need a function to do that. I have a couple different ones that I could show you.

Share this post


Link to post
Share on other sites

Okay, thanks, I got it. Thanks for your help.BTW, I caught another error, which was that I forgot to put another close-brace at the end of the entire expression. <_<Now, I'm going to try using MySQL and seeing where that leads me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.