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
syst3m
Forum Newbie
Posts: 1 Joined: Mon Feb 24, 2003 9:09 pm
Post
by syst3m » Mon Feb 24, 2003 9:09 pm
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) {
if (($username == "username") and ($password == "password")) {
location ("page.html"); # is the 'location' thing right?
}
else {
print ("Login Incorrect. Please try again.");
}
return # what????
}
?>
Mr. Tech
Forum Contributor
Posts: 205 Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia
Post
by Mr. Tech » Mon Feb 24, 2003 9:35 pm
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
}
?>