ARTICLE

Create Login page using PHP

Posted by Mike Steward Articles | PHP December 04, 2011
The login page is the most important web page in web-development, the login page provides secure access to websites for registered users only.
Reader Level:

Introduction

The login page is the most important web page in web-development, the login page provides secure access to websites for registered users only.  Logged in users get privileges to access the web page in a secure manner.

Let's see how to create a login page, Here are the steps to follow:

Step 1 : Firstly you need to design your login page.

w1.gif

Step 2 : HTML scripting for the above designed page.

<html>
    <
head>
        <
title>PHP Login</title>
     </
head>
<
body bgcolor="#FFFFCC">
   <center>
   <
h3>PHP LOGIN </h3>
   <
hr />
   <form method="post" action="login.php" >
     <table border="0" >
      <tr>
       <
td>
        <
B>User</B>
       </
td>
      <
td><input type="text" name="userid">
      </tr>
      <
tr>
       <
td><B>Password</B></td>
        <
td><input name="password" type="password"></input></td>
      </tr> <br/>
     <
tr>
      <
td><input type="submit" value="Submit"/>
      <td><input type="reset" value="Reset"/>
     </tr>
    </
table>
  </
form>
  </
center>
</
body>
</html>

saved it as login.html

Step 3 : Now we will create a database table named login1 having two columns named "username" & "password".

usernamepassword
DEEPAK DWIJ abc
SAKSHIsaki

You must have installed a XAMPP server in your pc, if you have then just run the services.

d9.gif

Type the http://localhost/phpmyadmin at your browser, you will get.

H.gif

Create your database table login1 , to know how to create table then go to http://www.c-sharpcorner.com/UploadFile/c8aa13/working-with-database-in-php/

Step 4 : After creating a login1 table, the role of PHP page starts now.

<html>
<
body bgcolor="#ffffCC">
<center>
<
h1><?php
$f_usr= $_POST["userid"];
$f_pswd= $_POST[
"password"];
$con=mysql_connect(
"localhost","root","");
if(! $con)
{
       
die('Connection Failed'.mysql_error());
}
mysql_select_db(
"phpdata",$con);
$result=mysql_query(
"select * from login1");
while($row=mysql_fetch_array($result))
{
   
if($row["username"]==$f_usr && $row["password"]==$f_pswd)
       
echo"Welcome : $f_usr";
   
else
        echo
"Sorry : $f_usr";
}
?>
</h1>
</
center>
</
body>
</html>

save this page by login.php

Step 5 : Now we going to run the login page, open Your browser and type http://localhost/deepak/login.html

w2.gif

Click the submit button then, if you are login successfully then. 

w3.gif

Unregistered user login then. 

w4.gif

After clicking Submit button. 

w5.gif
 

Login to add your contents and source code to this article
post comment
     

Hey i am getting an error- Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\oct\login.php on line 15plzz suggest a solution..

Posted by Nitish Hardeniya Feb 28, 2013

Hi....This is really nice article.http://dotnetpools.com/Article/ArticleDetiail/?articleId=24&title=Ajax%20Login%20Example%20Using%20Jquery%20%20In%20Asp.net

Posted by vinay singh Oct 02, 2012

great job.

Posted by kuldeep pathak Sep 21, 2012

Hi,Very good, & nice Work.Thanks.

Posted by Mohamad Ahmad Jul 03, 2012

Gud work mke !

Posted by Deepak Dwij Jan 07, 2012
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.