PHP tutorial - loging page


Login Page

In this page, you will learn to create a simple login page. The login page allows the user to input the user name and password. There is a submit button that will take the user to another page, welcome page. In each page in this example web application, there is a menu bar that contains the following items: Hoem, Programs, About us, and Contact Us. The menu items are defined a file called menu.php. The menu will be included to every page.

Here is the login.php page.

wlogin.php

<!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>Account Login</title>
</head>
<body>
<?php
include("menu.php");
?>

<form method="post" action="welcome.php">
<h2>Login </h2>
<table style="background-color: #CCC">

<tr>
<td>
User name:
</td>
<td>

<input type="text" name="txtuser" />
</td>
</tr>
<tr>
<td>
Password:
</td>

<td>
<input type="password" name="txtpwd" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="btsubmit" value="submit" />
</td>
</tr>
</table>
</form>

</body>
</html>

The content of the menu.php file that defines top-level menu is shown below:

menu.php

<style>
a{
color:#ffffff;

}
a:hover{
color:#399;
}
</style>
<div style="background-color: #C96">
<a href="home.html">Home</a>-
<a href="programs.html">Programs</a>-
<a href="aboutus.html">About Us</a>-
<a href="contact.html">Contact Us</a><br />
</div>

When the user clicks the the submit button on the login page, it will redirect the user to the welcome page. In the welcome page, there is a check to determine whether the account information is correct. If it is correct, simply display the "Welcome to my page" message. Otherwise, the message "Invalid login" displays. Here is the content of the welcome.php page.

login page

<?php

$username=$_POST['txtuser'];
$pwd=$_POST['txtpwd'];

if($username=="dara" && $pwd=="dara123"){
include("menu.php");
echo "<p style =\"color: #0000ff;font-size:18pt\"> Welcome to my home page</p>";
}
else
echo "<p style =\"color: #ff0000;font-size:18pt\">Invalid login</p>";

?>

welcome page


 



Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.