A Simple Password Page - I can't make one!!!

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

A Simple Password Page - I can't make one!!!

tricky77puzzle
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:

CODE
<?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:

CODE
<?php

$rightuser = "";
$rightpass = "1234567890";

?>


password.html:

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

 

 

 


Reply

t3jem
QUOTE(tricky77puzzle @ Mar 3 2008, 08:08 PM) *
password.php:

CODE
<?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:

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

CODE
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

 

 

 


Reply

jlhaslip
A single page will do that for you...

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

Reply

tricky77puzzle
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. laugh.gif

Now, I'm going to try using MySQL and seeing where that leads me.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : password

  1. Gahhh This Isn't Going Well Please Help! - It's a forgot password form in php! (12)
  2. Registration Form?! - Password Issue??? (6)
    How can I build the registration form with some additional function which is illustrated by attached
    file. When a user tries to type a password, that bar thing says neither it's strong nor weak, or
    medium. Just take a look at attachment...
  3. Password Strength / User Availablity Scripts ? - (2)
    many of u guys would already have noticed that now a days , on most of the websites , when some one
    sign in...as he puts his desired username in the textbox , the page shows that it is not available
    or it is available...without pushing any button etc.. and the second thing , when some one writes
    the password , on the same screen , it shows that password is weak or password is strong... i think
    it is done with php ... can some one give me a link to any page where i can access these scripts ?
    or some one can help me regarding this ?? Thanks for helping always....
  4. Phpbb Password Protector - Any Good Ones Out There? (3)
    I have searched and searhed and searched for a good Password Protection Mod for the PHPBB Forums,
    but i cannot find one that will work, i have uploaded the files necessary to the Admin/mods section,
    then i do what it says in the file that tells me how to do it, but they never work for me.. im
    Getting this.. QUOTE Warning: main(./extension.inc): failed to open stream: No such file or
    directory in /home/phillip/public_html/rpg/admin/mods/Password-protected forums
    0.5.1/phpbb_root_path/db_update.php on line 22 Warning: main(./extension.inc): failed to open
    stream: No...
  5. Mysql Password - (2)
    Hey guys quick question about trap 17s mysql version. How do i change the password to the database?
    I cant seem to find online help for this version anywhere. Any help is very apperciated!...
  6. creat password with php? - (6)
    how...



Looking for simple, password, page, make

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for simple, password, page, make

*MORE FROM TRAP17.COM*
advertisement



A Simple Password Page - I can't make one!!!



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE