PDA

View Full Version : Simple PHP password form



bluewalrus
10-11-2008, 07:14 PM
I'm trying to make a form only submitable after entering a username and password but can't seem to get it to work. The edit.php contains the php form there going to be editing.


<?php
$username = $_POST['user'];
$password = $_POST['password'];
if (user=="name1" || user=="name2") {
if (password=="thepassword") {
include("edit.php");
}
else
{
echo "Username or Password not entered correctly please try again.";
}
}
?>


The html that submits to that page...

<form method="post" action="word.php" style="border:#000000 2px solid; width:375px;">
Username:
<input type="text" name="user" size="35" />
<br />
Password:
<input type="password" name="password" size="35" /><br />
<input type="submit" value="Submit Password" style="text-align:center;" />
</center></form>

This is what the edit.php contains don't know if it's displayable with the include but i hope it is...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Edit Questions</title>
</head>

<body>
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
Your Name:
<input type="text" name="name" size="35" />
<br />

<textarea name="question" rows="4" cols="44"><?php
$myFile = "questions.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 20000000);
fclose($fh);
echo $theData;
?></textarea>
<br /><center>
<input type="submit" value="Send Your Question" style="text-align:center;" />
</center></form>
</body>
</html>



Thanks for any help and suggestions you can offer.

bluewalrus
10-13-2008, 02:04 PM
or another way...???

thetestingsite
10-13-2008, 02:30 PM
These lines:



if (user=="name1" || user=="name2") {
if (password=="thepassword") {


should be this:



if ($username=="name1" || $username=="name2") {
if ($password=="thepassword") {


Hope this helps.

bluewalrus
10-13-2008, 03:38 PM
Nope still no luck. I put what the include was suppose to bring in straight into the document but it didn't help. The password parts not being read for some reason. This is the php/ html mixture i have concocted:

<?php
$username = $_POST['user'];
$password = $_POST['password'];
if (username=="name1" || username=="name2") {
if (password=="password") {
?>
<form method="post" action="submitques.php" style="border:#000000 2px solid; width:375px;">
Your Name:
<input type="text" name="name" size="35" /><br />
<textarea name="question" rows="4" cols="44">
<?php
$myFile = "questions.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 20000000);
fclose($fh);
echo $theData;
?>
</textarea>
<?php
}
else
{
echo "Username or Password not entered correctly please try again.";
}
}
?>
Less the html and css stuff which can be seen here http://www.travelinchucks.com/word.php. The error message "username password not correct" doesn't come up. Seems to be ignoring it all together. The page thats submitting to this page is http://www.travelinchucks.com/log.php. Its all html with this form:

<form method="post" action="word.php" style="border:#000000 2px solid; width:375px;">
Username:
<input type="text" name="user" size="35" />
<br />
Password:
<input type="password" name="password" size="35" /><br />
<input type="submit" value="Edit Page" style="text-align:center;" />
</center></form>

allahverdi
10-13-2008, 03:50 PM
$username = $_POST['user'];
$password = $_POST['password'];
if ($username=="name1" || $username=="name2") {
if ($password=="password") {

bluewalrus
10-13-2008, 03:55 PM
oooo hah I knew i was missing something else thanks. Do you know why the error message isn't working though?

thetestingsite
10-13-2008, 07:19 PM
Try this for your else section:



<?php
}
}

else
{
echo "Username or Password not entered correctly please try again.";
}



Hope this helps.

bluewalrus
10-13-2008, 11:18 PM
That brings up "Parse error: parse error, unexpected '}' in /hsphere/local/home/crazychr/travelinchucks.com/word.php on line 68". Maybe because i closed the php then reopened it down more?

Code html and php:

<?php
$username = $_POST['user'];
$password = $_POST['password'];
if ($username=="name1" || $username=="name2") {
if ($password=="password") {
?>
<form method="post" action="submitques.php" style="border:#000000 2px solid; width:750px;">
<textarea name="question" rows="20" cols="90">
<?php
$myFile = "questions.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 20000000);
fclose($fh);
echo $theData;
?>
</textarea>
<input type="submit" value="Submit Changes" style="text-align:center; font-family:Geneva, Arial, Helvetica, sans-serif; font-size:14px;" />
</form>
<?php
}
}
else
{
echo "Username or Password not entered correctly please try again.";
}
}
?>

thetestingsite
10-14-2008, 12:51 AM
You have an extra closing bracket. Simply remove the highlighted:



<?php
$username = $_POST['user'];
$password = $_POST['password'];
if ($username=="name1" || $username=="name2") {
if ($password=="password") {
?>
<form method="post" action="submitques.php" style="border:#000000 2px solid; width:750px;">
<textarea name="question" rows="20" cols="90">
<?php
$myFile = "questions.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 20000000);
fclose($fh);
echo $theData;
?>
</textarea>
<input type="submit" value="Submit Changes" style="text-align:center; font-family:Geneva, Arial, Helvetica, sans-serif; font-size:14px;" />
</form>
<?php
}
}
else
{
echo "Username or Password not entered correctly please try again.";
}
}
?>


Hope this helps.

bluewalrus
10-14-2008, 02:28 AM
yea thats it thank you.