PEAR Articles
  Home arrow PEAR Articles arrow Page 3 - User Authentication for a PEAR CMS
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
PEAR ARTICLES

User Authentication for a PEAR CMS
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-10-15

    Table of Contents:
  • User Authentication for a PEAR CMS
  • Code Explained
  • String or Numeric
  • Granting Access to the CMS

  • 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


    User Authentication for a PEAR CMS - String or Numeric


    (Page 3 of 4 )

    After determining whether the values entered are not empty, we check to see if the values entered here are string or numeric. Since we only expect values that are of type string, it is easy to check with the is_numeric() function, which evaluates the parameter that it is passed:

    //make sure fields are string

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

    $err=true;

    $error .="The username you entered has a invalid format.<br>";


    }

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

    $err=true;

    $error .="The password that you entered has an invalid format<br>.";

    }

    If the passed values are not of type string, then we set the $err variable to true. Later on in the script we will test this Boolean variable to determine if certain actions should be taken. The code then checks to see if the $err variable is true or false and then proceeds accordingly. If the $err variable is true then it means somewhere along the line there was an error, therefore we cannot continue with the SQL query to check if the user exists in the database. On the other hand, if there was no error, the code continues to call the db class and connx.php file to run a query:

    if(!$err){

    include 'db.php';

    include 'connx.php';

    As already discussed, the db class contains methods that we will be using to run database queries, and the connx.php file contains the database connection information that is needed to connect to the database. Once the data is available to the script, it is used for the sql query. Since we are using data that is coming from an untrusted source (in this case the HTML form), it has to be filtered. In our case we have two pieces of information coming from outside the application, the username and password. This data will be used in the SQL query, we need to filter these items. To filter the data we use the mysq_real_escape_string() function as shown in the code below:

    $username=mysql_real_escape_string($_POST['uname']);

    $pw=mysql_real_escape_string($_POST['upass']);

    Once the data is filtered, we then run a query to determine if this user exists in the database:

    $sql = "SELECT * FROM users WHERE uname='".$username."' AND upass='".$pw."'";

    $res = $db->query($sql);

    We then check to see if any errors have been returned while executing the query. We do this by checking DB's isError() function and then printing out the message:

    if (DB::isError($res)) {

    die($res->getMessage());

    }


    //***********************************************************

    More PEAR Articles Articles
    More By David Web


     

    PEAR ARTICLES ARTICLES

    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





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