Home arrow PHP arrow Page 3 - Project Management: Authentication

The Login Code - PHP

I recently completed an article series in which we built a project management application. Every application that wants to control access to its resources has an access control mechanism that will verify if a user is allowed to use the particular application. A project management application is a good candidate for such a control. In this four-part series, we will build an authentication system for the application.

TABLE OF CONTENTS:
  1. Project Management: Authentication
  2. Create the Table
  3. The Login Code
  4. Login Code continued
By: David Web
Rating: starstarstarstarstar / 3
July 28, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The first couple of lines includes the database connection file, which contains our database connection credentials, and also the functions file, which contains the functions that we are going to use for user verification. Some of the lines also enable us to initialize variables:


include "dbcon.php";

include "functions.php";

//initialise variables

$err=false;

$errmsg="";


The $err and $errmsg variables are used to collect error messages across the script, and depending on whether there are errors, will be displayed on the login form. The $err variable is of type Boolean, and is initially set to false. In most of the scripts in this application, it will decide whether or not SQL queries can be run. The next couple of lines basically checks to see if the form has been submitted:


//is form submitted?

if(isset($_POST['submit'])){


Then tests to see if the form fields are empty or not:


//check that the form values are not empty, if so, set errormsg value

if(empty($_POST['uname'])){

$errmsg="The username field is empty, please enter a username<br>";

$err=true;

}


If they are empty, the $err variable is set to true and the $errmsg variable is assigned a error message:


if(empty($_POST['upass'])){

$err=true;

$errmsg .="The password field is empty, please enter password<br>";

}


Another test is performed on the username that is submitted. The test is to verify that the username is in the correct format. Remember that our usernames must be in the format name.surname:


//check that the username is in correct format

if(!checkformat($_POST['uname'])){

$err=true;

$errmsg .="The username that you entered has a incorrect format.<br>";

}


The checkformat() function is located in the functions.php file and has the following code:


function checkformat($aUsername){

if(eregi('^[a-z]+[.]+[a-z]+$',$aUsername))

return TRUE;

else

return FALSE;

}


It makes use of regular expression by matching a pattern against a given string value. You can of course use other ways to verify the username format.



 
 
>>> More PHP Articles          >>> More By David Web
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: