PHP
  Home arrow PHP arrow Page 5 - Creating a Credit Card Validation Class Wi...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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

Creating a Credit Card Validation Class With PHP
By: David Rusik
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 36
    2002-02-25

    Table of Contents:
  • Creating a Credit Card Validation Class With PHP
  • Credit card validation
  • Creating the CCreditCard class
  • Creating the CCreditCard class (contd.)
  • Using our CCreditCard class
  • Conclusion

  • 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


    Creating a Credit Card Validation Class With PHP - Using our CCreditCard class


    (Page 5 of 6 )

    Create a new file called testcc.php and save it in the same directory as the class.creditcard.php file. Enter the following code into testcc.php:

    <?php include('class.creditcard.php'); ?>

    <?php

    global $submit;



    if(!isset($submit))

    {

    ?>

    <h2>Validate Credit Card</h2>

    <form name="frmCC" action="cctest.php" method="post">

    Cardholders name: <input type="text" name="ccName"><br>

    Card number: <input type="text" name="ccNum"><br>

    Card type: <select name="ccType">

    <option value="1">mastercard</option>

    <option value="2">Visa</option>

    <option value="3">Amex</option>

    <option value="4">Diners</option>

    <option value="5">Discover</option>

    <option value="6">JCB</option>

    </select><br>

    Expiry Date: <select name="ccExpM">

    <?php

    for($i = 1; $i < 13; $i++)

    { echo '<option>' . $i . '</option>'; }



    ?>

    </select>

    <select name="ccExpY">

    <?php

    for($i = 2002; $i < 2013; $i++)

    { echo '<option>' . $i . '</option>'; }



    ?>

    </select><br><br>

    <input type="submit" name="submit" value="Validate">

    </form>

    <?

    }

    else

    {

    // Check if the card is valid

    global $ccName;

    global $ccNum;

    global $ccType;

    global $ccExpM;

    global $ccExpY;



    $cc = new CCreditCard($ccName, $ccType, $ccNum, $ccExpM, $ccExpY);

    ?>

    <h2>Validation Results</h2>

    <b>Name: </b><?php echo $cc->Name(); ?><br>

    <b>Number: </b><?php echo $cc->SafeNumber('x', 6); ?><br>

    <b>Type: </b><?php echo $cc->Type(); ?><br>

    <b>Expires: </b><?php echo $cc->ExpiryMonth() . '/' . $cc->ExpiryYear(); ?><br><br>



    <font color="blue" size="2"><b>



    <?php



    if($cc->IsValid())

    echo "VALID CARD";

    else

    echo "INVALID CARD";



    echo "</b></font>";

    }

    ?>


    Run the script in your browser. Here are two screen shots from my browser. The first one shows the HTML form, and the second shows the output once the form is submitted:

    Entering the cards details

    The results of the card validation

    More PHP Articles
    More By David Rusik


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT