Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Online Shopping in PHP

  • 14-10-2004 10:23am
    #1
    Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭


    Does anyone know how i can do credit card verification for an online shop in PHP? would it be possible to write it myself or would i have to download a class for it? any help is appreciated.


Comments

  • Moderators, Politics Moderators Posts: 41,229 Mod ✭✭✭✭Seth Brundle


    How are you going to verify someones credit card?
    You need to pass their info onto the likes of realex or whatever.


  • Closed Accounts Posts: 7,563 ✭✭✭leeroybrown


    If you're talking about doing actual credit card transactions (as opposed to some demo for a project) then you'll need to go through a company who are authorised for online transaction validation. They'll supply the necessary secure e-commerce plugins for your transactions.


  • Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭The_B_Man


    no sorry, i should've been clearer. its not for real. it'd be more for the project demo scenario than for actual credit card transactions. i'm lookin for something along the lines of making sure they're all numbers and in the format of a proper credit card ie 15 digits or however many it is.


  • Moderators, Politics Moderators Posts: 41,229 Mod ✭✭✭✭Seth Brundle


    then just check that it is 16 digits long, they enter the type of card, its expiry date and maybe the 3 digit serial code on the back of the card.


  • Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭The_B_Man


    Thanks but how do i check it for numbers? whats the name of the function? i know there was one in ASP, i think, called "isnumeric", but i dont know what it is in PHP. I'm just tryin to get this stuff ready. i havent actually started coding and im just starting to actually learn PHP, so forgive me for being a little clueless.


  • Advertisement
  • Moderators, Politics Moderators Posts: 41,229 Mod ✭✭✭✭Seth Brundle




  • Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭The_B_Man


    nice thanx.


  • Registered Users, Registered Users 2 Posts: 912 ✭✭✭chakotha


    This is a way of validating card number formats I came across.

    http://www.beachnet.com/~hstiles/cardtype.html

    A function to do it is
    [PHP]<?
    /************************************************************************
    *
    * CCVal - Credit Card Validation function.
    *
    * Copyright (c) 1999 Holotech Enterprises. All rights reserved.
    * You may freely modify and use this function for your own purposes. You
    * may freely distribute it, without modification and with this notice
    * and entire header intact.
    *
    * This function accepts a credit card number and, optionally, a code for
    * a credit card name. If a Name code is specified, the number is checked
    * against card-specific criteria, then validated with the Luhn Mod 10
    * formula. Otherwise it is only checked against the formula. Valid name
    * codes are:
    *
    * mcd - Master Card
    * vis - Visa
    * amx - American Express
    * dsc - Discover
    * dnc - Diners Club
    * jcb - JCB
    *
    * A description of the criteria used in this function can be found at
    * http://www.beachnet.com/~hstiles/cardtype.html. If you have any
    * questions or comments, please direct them to ccval@holotech.net
    *
    * Alan Little
    * Holotech Enterprises
    * http://www.holotech.net/
    * September 1999
    *
    ************************************************************************/

    function CCVal($Num, $Name = 'n/a') {

    // Innocent until proven guilty
    $GoodCard = true;

    // Get rid of any non-digits
    $Num = ereg_replace("[^[:digit:]]", "", $Num);

    // Perform card-specific checks, if applicable
    switch ($Name) {

    case "mcd" :
    $GoodCard = ereg("^5[1-5].{14}$", $Num);
    break;

    case "vis" :
    $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
    break;

    case "amx" :
    $GoodCard = ereg("^3[47].{13}$", $Num);
    break;

    case "dsc" :
    $GoodCard = ereg("^6011.{12}$", $Num);
    break;

    case "dnc" :
    $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
    break;

    case "jcb" :
    $GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
    break;
    }

    // The Luhn formula works right to left, so reverse the number.
    $Num = strrev($Num);

    $Total = 0;
    for ($x=0; $x<strlen($Num); $x++) {
    $digit = substr($Num,$x,1);

    // If it's an odd digit, double it
    if ($x/2 != floor($x/2)) {
    $digit *= 2;
    // If the result is two digits, add them
    if (strlen($digit) == 2)
    $digit = substr($digit,0,1) + substr($digit,1,1);
    }
    // Add the current digit, doubled and added if applicable, to the Total
    $Total += $digit;
    }
    // If it passed (or bypassed) the card-specific check and the Total is
    // evenly divisible by 10, it's cool!
    if ($GoodCard && $Total % 10 == 0) return true; else return false;

    return true;
    }
    if (CCVal("4111111111111111", "vsa")) {
    echo("Good Card");
    } else {
    echo("Bad Card");
    }
    ?>
    [/PHP]
    You might want to test it on the various cards using test numbers. I have only tested it for Visa and Mastercard


Advertisement