Page 1 of 1

PHP newbie

Posted: Mon Feb 24, 2003 9:09 pm
by syst3m
I am trying to create a login form where someone enters a username and password and if they are right, the script will let them in. I don't know where to start. I was thinking maybe a function:

Code: Select all

<form action="index.php" method="???POST???">
 USERNAME:<input type="text" name="username">
 PASSWORD:<input type="password" name="password">
 <input type="submit" value="Login">
</form>
<?php
#how do I call the function?
#maybe: login($username, $password); ???
function login($username, $password) &#123;
 if (($username == "username") and ($password == "password")) &#123;
  location ("page.html"); # is the 'location' thing right?
 &#125;
 else &#123;
  print ("Login Incorrect. Please try again.");
 &#125;
 return # what????
&#125;
?>

Posted: Mon Feb 24, 2003 9:35 pm
by Mr. Tech
If ther is only one password you want you could try this:

Code: Select all

<?php
if ($action == "login") {
if ($username == "username" && $password == "password") { 
  include("page.html");
} 
else { 
  print ("Login Incorrect. Please try again."); 
} 
}
else {
?>
<form action="index.php" method="GET"> 
<input type="hidden" name="action" value="login">
USERNAME:<input type="text" name="username"> 
PASSWORD:<input type="password" name="password"> 
<input type="submit" value="Login"> 
</form> <?php
}
?>