PHP
  Home arrow PHP arrow Page 3 - Project Management: Authentication
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Project Management: Authentication
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-07-28


    Table of Contents:
  • Project Management: Authentication
  • Create the Table
  • The Login Code
  • Login Code continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Project Management: Authentication - The Login Code
    ( Page 3 of 4 )

    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT