Page 1 of 1

Php error

PostPosted: 26. July 2007 17:05
by arjita
Attached below is my code for a php script (it has no database look up required)..I can't get what I need to print.Also how can I encrypt the password.Any help would be appreciated ..Thanks


Code: Select all
<!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>Untitled Document</title>
<?php
$username = $_POST['username'];
$password = $_POST['password'];

if (($username == "Arjita") && (password == "sameer")){

print("Welcome Arjita");
}
else
{
   print("you are not authorized to vie this ");
}

?>
</head>

<body>
<p>
  <input name="username" type="text" />
</p>

  <input name="password" type="text" />

<p>&nbsp;</p>
<p>
  <input type = "Submit" name = "Submit1" value = "Login" />
</p>

<Form name ="form1" Method ="POST" Action ="C:\xampp\htdocs\Login.php">
</FORM>
</body>
</html>

PostPosted: 26. July 2007 17:24
by glitzi85
Hello,

try out this:

Code: Select all
<!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>Untitled Document</title>
</head>
<body>
<?php
if(($_POST['username'] == 'Arjita') && (md5($_POST['password']) == 'd524813536b71639999ba12bdb3621a8')){
 echo "Welcome Arjita";
}else{
 echo "You are not authorized to view this");
}
?>
<form action="./Login.php" method="post">
  Username: <input type="text" name="username">
  Password: <input type="password" name="password">
  <input type="submit" value="Login">
</form>
</body>
</html>


Normally you would not give out the formular any more if login is suceed, but for your test this is not neccessary.

For further Information please also refer to the PHP-Manual located here: http://www.php.net/manual/en/

To prevent your potentially next question: Save the File in C:\xampp\htdocs\ as Login.php (exactly in this notation!). Then open your Browser and load http://localhost/Login.php Your Site should be loaded (if you startet the Apache Webserver).

glitzi