Creating a Login Form Using PHP and Mysql

Hello Guys Welcome to Coding Gurus Online Portal ...!

The most essential pages in a web application are Registration form and Login Form, so here is how to go about to create one for your project.

Overview

PHP login script is used to provide user authentication for PHP website. This script will be executed on submitting user login details such as username/email and password.In this article, we are going to use How a Login Script works and we also create User Dashboard with PHP sessions.

Steps

In this tutorial, we are going to create only 4 files ,
1. Create table coding in database codinggurus.
2. Create file login.php.
3. Create file connection.php.
4. Create file dashboard.php.
5. Create file logout.php.
6. test it ...!

PHP Login Sessions

After getting login credentials from user, we need to compare with database to check whether they are valid or not. If they are correct,we will declare sessions.Using these session information, we ensure that user is logged in through out the website. These login session id's are preserved until the user is loged out. While logout, these sessions are destroyed.

For example we will declare sessions as $_SESSION["member_id"], $_SESSION["display_name"].

Query to Create A Table coding.

CREATE TABLE `members` (
`id` int(4) NOT NULL auto_increment,
`username` varchar(65) NOT NULL ,
`password` varchar(65) NOT NULL ,
PRIMARY KEY (`id`)
) ;

Creating a file login.php

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

Back Next