PHP
  Home arrow PHP arrow A Login System for a PHP Email Applica...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

A Login System for a PHP Email Application
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 19
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · Hope this article on Emailling with PHP/MYSQL will be useful to someone.
     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway