<form action="login.php" method="post">
Username:
<input type="input" name="username">
<br>
Password:
<input type="password" name="password">
<br>
<input type="submit" value="Login">
</form>
Now you have a simple for with inputs for the account login. So, what now? you have to add some simple PHP. To start make a new file in the same directory called "login.php" then add the following PHP code anywhere on the page:
<?php
$user = $_POST["username"];
$pass= $_POST["password"];
function echohtml($name) {
echo "<tt>";
echo "<h1>";
echo "Hello, $name";
echo "</h1>";
echo "</tt>";
}
function wrong() {
echo "<tt>";
echo "<h1>";
echo "Wrong Username/Password";
echo "</h1>";
echo "</tt>";
}
if($user == "add username here" and $pass == " add password here") {
echohtml($user);
}
else {
wrong();
}
?>
The PHP is actually very simple when you break it down; If the username and password is correct then call echohtml() if not then call wrong(). In those functions you can echo out whatever you want. Hope you enjoyed this brief writing on account logins in PHP.
No comments:
Post a Comment