PHP
  Home arrow PHP arrow A Login System for a PHP Email Application
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? 
Google.com  
PHP

A Login System for a PHP Email Application
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 22
    2006-11-01


    Table of Contents:
  • A Login System for a PHP Email Application
  • The code: form verification
  • The code: logging out and registration
  • The code: form handling and user profile

  • 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


    A Login System for a PHP Email Application
    ( Page 1 of 4 )

    We know from the previous article that the user ID is very important, in that it is used to retrieve various information from the database at various stages of the application. The login form sets this userID when you log in. It is the login system that will be the focus of this second part in a four-part series.

    For anyone to use the application, they have to be authenticated (be a registered user of the system) or be given an opportunity to become a member. This is what the login system primarily is for. Below is a screen shot of the login page.

    The code: connecting and logging in

    The login script presents a form in which the user must enter his/her username and password. It is then processed by the various code bits on the page and the appropriate action is taken. Let's go through the various scripts involved.

    Connect.php. This script is included on any page that uses the database. It contains the information that connects the application to the database:

    <?php
    $dbname="mail";
    $host="localhost";
    $dbh=mysql_connect($host) or die ('I cannot connect to the
    database because: ' . mysql_error());
    mysql_select_db($dbname) or die('I cannot select the database
    because: ' . mysql_error());
    ?>

    At each stage of the connection attempt, the code makes provisions for errors. This is in case you try to connect to a non-existing database or to a non-existing host.

    Login.php. This script presents a login form to the user. This form takes the username and password of the user. The form is presented in a table, as you can see from the code:

    Form:

    <form action="login.php" method="post">
                <table width="50%" border="0" align="center"
    cellspacing="1" class="block">
          <tr>
            <td width="13%" colspan="2"><img src="images/login.png"
    width="400" height="130" /></td>
                            </tr>
          <tr>
           <td width="87%" valign="bottom" colspan="2"><font color =
    "#ff000" size = "5"><? if(isset($error)){
                            echo $error;
                            }elseif(isset($_GET['msg'])){
                            echo "You are now registered. Please
    login below.";?>
                            </td>
          <? } ?>
            </tr>
          <tr class="table">
            <td>&nbsp;</td>
            <td>Login here: </td>
          </tr>
          <tr>
            <td>Username</td>
            <td><input name="uname" type="text" id="uname"
    value="jacques" size="40" /></td>
          </tr>
          <tr>
            <td>Password</td>
            <td><input name="pw" type="password" id="pw" value="pass"
    size="40" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="submit"
    value="Login" /></td>
          </tr>
        </table>
                            </form>

    In addition to taking user input, the form also displays error messages from the actual login script:

    if(isset($error)){
                            echo $error;
                            }elseif(isset($_GET['msg'])){
                            echo "You are now registered. Please
    login below.";?>
    }

    The $error variable  is set in the actual code that processes the username and password.



     
     
    >>> More PHP Articles          >>> More By Leidago
     

       

    PHP ARTICLES

    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek