PHP
  Home arrow PHP arrow Page 3 - Building Site Registration for Web Application Security
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

Building Site Registration for Web Application Security
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2008-10-27


    Table of Contents:
  • Building Site Registration for Web Application Security
  • The Code Explained
  • Username and Password
  • The HTML Form 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


    Building Site Registration for Web Application Security - Username and Password
    ( Page 3 of 4 )


    We then compare the two passwords that the user provided in the form. This is just to make sure that the passwords match before we insert it into the database:


    if("$pw1" !== "$pw2" ){

    print "your confirmation password has been mistyped or is empty,please try again";

    $conf="your confirmation password has been mistyped or is empty,please try again";

    exit;

    }

    The next step is to check that the user name which the new user provided does not already exist in the database. To do this we need to connect to the database server, and then run a query to see if the username is found:

    //connect to the db server , check if uname exist

    include('../config.inc');

    $query="Select name from user where uname='$name'";

    $result= mysql_query($query);

    We use the $num variable to see if the query returned any results. If there are results, then it means that there already is a name that is the same as the one provided by the user, in which case an appropriate error message is sent:

    $num=mysql_num_rows($result);

    if ($num > 0) {//Username already exist

    print "The username is already taken,please try again";

    $taken="The username is already taken,please try again";

    print "<p><a href=http://localhost/loginscript/register.php>Click here to try again.</a></p>";

    exit;

    Otherwise, the name provided by the user does not exists in the database, so the new details of the user are inserted in the database, the appropriate query string value is set, and the user is directed to the login page:

    }else{

    //if username does not exist insert user details

    $query="INSERT INTO users (uname, pw,email) VALUES ('$name',password('$pw1'),'$email')"

    if (@mysql_query ($query)) {

    //print "Your details have been added";

    header("location:login.php?reg=1");

    exit;

    }

    }

    }

    }

    The HTML form is responsible for collecting the registration information from the user. The actual form code is detailed and explained below. 

    The first line in the code declares the form header, which includes the name of the form, the method that the form uses to send information, onsubmit and finally the name of the script that processes the form data:

    <form name="form1" action="register.php" method="post" onSubmit="return checkform(this)" >


    A table is then created that will contain the actual form elements:


    <table width="657" border="0">

    <tr>

    <td width="122"><div align="left">Name</div></td>


    The first element of the form takes the name of the user:


    <td width="525"><input name="name" type="text" size="40"></td>

    </tr>

    <tr>



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

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - 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





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