PHP newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
syst3m
Forum Newbie
Posts: 1
Joined: Mon Feb 24, 2003 9:09 pm

PHP newbie

Post 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;
?>
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post 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
}
?>
Post Reply