PDA

View Full Version : Password protection


Vectar
10-17-2006, 07:18 PM
I have a problem with a passowrd protected page.

I need this file:
Admin.php

<?php
include("./dbconnect.php");
if(!empty($titel)) {
$titel = addslashes($titel);
$bericht = addslashes($bericht);

$sql = "INSERT INTO nieuws (id, titel, bericht) VALUES ('NULL', '$titel','$bericht')";
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
echo "Database Updated.";
} else {
?>
<link href="admin_style.css" rel="stylesheet" type="text/css" />
<form name="nieuws" method="post" action="<?php echo $PHP_SELF; ?>">
<p><strong>Please fill out all of the following fields:</strong></p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="95" height="25">Nieuws/Titel*:</td>
<td width="948">
<input type="text" name="titel" size="50"></td>
</tr>
<tr>
<td width="95" height="25">Bericht*:</td>
<td width="948" rowspan="2">
<font size="1">
<textarea name="bericht" rows=10 cols=37></textarea>
</font></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form> <?php
}//end this function
?>

to be password protected with the use of this form.

login.html

<html>
<head>
<title>Login</title>
</head>

<body>
<form name="login" method="post" action="protected.php">
Username:
<input name="formuser" type="text" id="formuser">
<br>
Password:
<input name="formpass" type="password" id="formpass">
<br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</form>
</body>
</html>

Now i need to add this script into my admin.php and i should work. Thats what the tutorial says but i can not make it work. When i add my content to the protected area it just keeps given errors.

<?php
$user = "your_username_here";
$password = "your_password_here";
$formuser = $_POST["formuser"];
$formpass = $_POST["formpass"];
if(($formuser == $user) && ($formpass == $password)){
//Protected Content here
}
else {
echo("Login Incorrect, Please click back and try again");
}
?>

peptobismol
10-18-2006, 07:15 PM
in your form, try
<form name="login" method="post" action="protected.php">
Username:
<input name="formuser" type="text" name="formuser">
<br>
Password:
<input name="formpass" type="password" name="formpass">
<br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</form>
</body>


'name' is what is expected.