php实现通用的信用卡验证类,php通用信用卡验证
本文实例讲述了php实现通用的信用卡验证类。分享给大家供大家参考。
原文说明如下:
Credit Card Validation Solution (PHP Edition)
Version 3.5
Description
Credit Card Validation Solution™ uses a four step process to ensure credit card numbers are keyed in correctly. This procedure accurately checks cards from American Express, Australian BankCard, Carte Blache, Diners Club, Discover/Novus, JCB, MasterCard and Visa.
For more information, please read the comments in the code itself.
Installation Instructions
Select the text between the two lines indicated, below.
Copy the text.
Open up a text editor.
Paste the text.
Save that file. When saving it, make sure to:
save it in a directory on your webserver, and
name it with an extension that your server will recognize needs parsing by PHP.
To see it in action, open up that file in your web browswer.
具体代码如下:
<?php # ------------------------------------------------------------------------ # Credit Card Validation Solution, version 3.5 PHP Edition # 25 May 2000 # # COPYRIGHT NOTICE: # a) This code is property of The Analysis and Solutions Company. # b) It is being distributed free of charge and on an "as is" basis. # c) Use of this code, or any part thereof, is contingent upon leaving # this copyright notice, name and address information in tact. # d) Written permission must be obtained from us before this code, or any # part thereof, is sold or used in a product which is sold. # e) By using this code, you accept full responsibility for its use # and will not hold the Analysis and Solutions Company, its employees # or officers liable for damages of any sort. # f) This code is not to be used for illegal purposes. # g) Please email us any revisions made to this code. # # Copyright 2000 http://www.AnalysisAndSolutions.com/code/ # The Analysis and Solutions Company info@AnalysisAndSolutions.com # ------------------------------------------------------------------------ # # DESCRIPTION: # Credit Card Validation Solution uses a four step process to ensure # credit card numbers are keyed in correctly. This procedure accurately # checks cards from American Express, Australian BankCard, Carte Blache, # Diners Club, Discover/Novus, JCB, MasterCard and Visa. # # CAUTION: # CCVS uses exact number ranges as part of the validation process. These # ranges are current as of 20 October 1999. If presently undefined ranges # come into use in the future, this program will improperly deject card # numbers in such ranges, rendering an error message entitled "Potential # Card Type Discrepancy." If this happens while entering a card & type # you KNOW are valid, please contact us so we can update the ranges. # # POTENTIAL CUSTOMIZATIONS: # * If you don't accept some of these card types, edit Step 2, using pound # signs "#" to comment out the "elseif," "$CardName" and "$ShouldLength" # lines in question. # * Additional card types can be added by inserting new "elseif," # "$CardName" and "$ShouldLength" lines in Step 2. # * The three functions here can be called by other PHP documents to check # any number. # # CREDITS: # We learned of the Mod 10 Algorithm in some Perl code, entitled # "The Validator," available on Matt's Script Archive, # http://worldwidemart.com/scripts/readme/ccver.shtml. That code was # written by David Paris, who based it on material Melvyn Myers reposted # from an unknown author. Paris credits Aries Solis for tracking down the # data underlying the algorithm. At the same time, our code bears no # resemblance to its predecessors. CCValidationSolution was first written # for Visual Basic, on which Allen Browne and Rico Zschau assisted. # Neil Fraser helped prune down the OnlyNumericSolution() for Perl. function CCValidationSolution ($Number) { global $CardName; # 1) Get rid of spaces and non-numeric characters. $Number = OnlyNumericSolution($Number); # 2) Do the first four digits fit within proper ranges? # If so, who's the card issuer and how long should the number be? $NumberLeft = substr($Number, 0, 4); $NumberLength = strlen($Number); if ($NumberLeft >= 3000 and $NumberLeft <= 3059) { $CardName = "Diners Club"; $ShouldLength = 14; } elseif ($NumberLeft >= 3600 and $NumberLeft <= 3699) { $CardName = "Diners Club"; $ShouldLength = 14; } elseif ($NumberLeft >= 3800 and $NumberLeft <= 3889) { $CardName = "Diners Club"; $ShouldLength = 14; } elseif ($NumberLeft >= 3400 and $NumberLeft <= 3499) { $CardName = "American Express"; $ShouldLength = 15; } elseif ($NumberLeft >= 3700 and $NumberLeft <= 3799) { $CardName = "American Express"; $ShouldLength = 15; } elseif ($NumberLeft >= 3528 and $NumberLeft <= 3589) { $CardName = "JCB"; $ShouldLength = 16; } elseif ($NumberLeft >= 3890 and $NumberLeft <= 3899) { $CardName = "Carte Blache"; $ShouldLength = 14; } elseif ($NumberLeft >= 4000 and $NumberLeft <= 4999) { $CardName = "Visa"; if ($NumberLength > 14) { $ShouldLength = 16; } elseif ($NumberLength < 14) { $ShouldLength = 13; } else { echo "<br /><em>The Visa number entered, $Number, in is 14 digits long.<br />Visa cards usually have 16 digits, though some have 13.<br />Please check the number and try again.</em><br />n"; return FALSE; } } elseif ($NumberLeft >= 5100 and $NumberLeft <= 5599) { $CardName = "MasterCard"; $ShouldLength = 16; } elseif ($NumberLeft == 5610) { $CardName = "Australian BankCard"; $ShouldLength = 16; } elseif ($NumberLeft == 6011) { $CardName = "Discover/Novus"; $ShouldLength = 16; } else { echo "<br /><em>The first four digits of the number entered are $NumberLeft. <br />If that's correct, we don't accept that type of credit card.<br />If it's wrong, please try again.</em><br />n"; return FALSE; } # 3) Is the number the right length? if ($NumberLength <> $ShouldLength) { $Missing = $NumberLength - $ShouldLength; if ($Missing < 0) { echo "<br /><em>The $CardName number entered, $Number, is missing " . abs($Missing) . " digit(s).<br />Please check the number and try again.</em><br />n"; } else { echo "<br /><em>The $CardName number entered, $Number, has $Missing too many digit(s).<br />Please check the number and try again.</em><br />n"; } return FALSE; } # 4) Does the number pass the Mod 10 Algorithm Checksum? if (Mod10Solution($Number) == TRUE) { return TRUE; } else { echo "<br /><em>The $CardName number entered, $Number, is invalid.<br />Please check the number and try again.</em><br />n"; return FALSE; } } function OnlyNumericSolution ($Number) { # Remove any non numeric characters. # Ensure number is no more than 19 characters long. return substr( ereg_replace( "[^0-9]", "", $Number) , 0, 19); } function Mod10Solution ($Number) { $NumberLength = strlen($Number); $Checksum = 0; # Add even digits in even length strings # or odd digits in odd length strings. for ($Location = 1 - ($NumberLength % 2); $Location < $NumberLength; $Location += 2) { $Checksum += substr($Number, $Location, 1); } # Analyze odd digits in even length strings # or even digits in odd length strings. for ($Location = ($NumberLength % 2); $Location < $NumberLength; $Location += 2) { $Digit = substr($Number, $Location, 1) * 2; if ($Digit < 10) { $Checksum += $Digit; } else { $Checksum += $Digit - 9; } } # Is the checksum divisible by ten? return ($Checksum % 10 == 0); } # ----------- BEGIN SAMPLE USER INTERFACE SECTION ------------ # # This section provides a simple sample user interface for the # Credit Card Validation functions. It generates an HTML form # where you enter a card number to check. # # If a number has been posted by the form, check it. if ( isset($Number) ) { # Get rid of spaces and non-numeric characters in posted # numbers so they display correctly on the input form. $Number = OnlyNumericSolution($Number); if (CCValidationSolution($Number) == TRUE) { echo "<br />The $CardName number entered, $Number, <em>is</em> valid.<br />n"; } } else { $Number = ""; } # Setup an input form. Posting it calls this page again. echo "<form method="post" action="$REQUEST_URI">n"; echo "<br />Credit Card Number: <input type="text" name="Number" value="$Number">n"; echo "<input type="Submit" name="submitr" value="Check its Validity">n"; echo "</form><br />n"; # # ------------ END SAMPLE USER INTERFACE SECTION ------------- ?>
希望本文所述对大家的php程序设计有所帮助。

PHP는 현대적인 프로그래밍, 특히 웹 개발 분야에서 강력하고 널리 사용되는 도구로 남아 있습니다. 1) PHP는 사용하기 쉽고 데이터베이스와 완벽하게 통합되며 많은 개발자에게 가장 먼저 선택됩니다. 2) 동적 컨텐츠 생성 및 객체 지향 프로그래밍을 지원하여 웹 사이트를 신속하게 작성하고 유지 관리하는 데 적합합니다. 3) 데이터베이스 쿼리를 캐싱하고 최적화함으로써 PHP의 성능을 향상시킬 수 있으며, 광범위한 커뮤니티와 풍부한 생태계는 오늘날의 기술 스택에 여전히 중요합니다.

PHP에서는 약한 참조가 약한 회의 클래스를 통해 구현되며 쓰레기 수집가가 물체를 되 찾는 것을 방해하지 않습니다. 약한 참조는 캐싱 시스템 및 이벤트 리스너와 같은 시나리오에 적합합니다. 물체의 생존을 보장 할 수 없으며 쓰레기 수집이 지연 될 수 있음에 주목해야합니다.

\ _ \ _ 호출 메소드를 사용하면 객체를 함수처럼 호출 할 수 있습니다. 1. 객체를 호출 할 수 있도록 메소드를 호출하는 \ _ \ _ 정의하십시오. 2. $ obj (...) 구문을 사용할 때 PHP는 \ _ \ _ invoke 메소드를 실행합니다. 3. 로깅 및 계산기, 코드 유연성 및 가독성 향상과 같은 시나리오에 적합합니다.

섬유는 PHP8.1에 도입되어 동시 처리 기능을 향상시켰다. 1) 섬유는 코 루틴과 유사한 가벼운 동시성 모델입니다. 2) 개발자는 작업의 실행 흐름을 수동으로 제어 할 수 있으며 I/O 집약적 작업을 처리하는 데 적합합니다. 3) 섬유를 사용하면보다 효율적이고 반응이 좋은 코드를 작성할 수 있습니다.

PHP 커뮤니티는 개발자 성장을 돕기 위해 풍부한 자원과 지원을 제공합니다. 1) 자료에는 공식 문서, 튜토리얼, 블로그 및 Laravel 및 Symfony와 같은 오픈 소스 프로젝트가 포함됩니다. 2) 지원은 StackoverFlow, Reddit 및 Slack 채널을 통해 얻을 수 있습니다. 3) RFC에 따라 개발 동향을 배울 수 있습니다. 4) 적극적인 참여, 코드에 대한 기여 및 학습 공유를 통해 커뮤니티에 통합 될 수 있습니다.

PHP와 Python은 각각 고유 한 장점이 있으며 선택은 프로젝트 요구 사항을 기반으로해야합니다. 1.PHP는 간단한 구문과 높은 실행 효율로 웹 개발에 적합합니다. 2. Python은 간결한 구문 및 풍부한 라이브러리를 갖춘 데이터 과학 및 기계 학습에 적합합니다.

PHP는 죽지 않고 끊임없이 적응하고 진화합니다. 1) PHP는 1994 년부터 새로운 기술 트렌드에 적응하기 위해 여러 버전 반복을 겪었습니다. 2) 현재 전자 상거래, 컨텐츠 관리 시스템 및 기타 분야에서 널리 사용됩니다. 3) PHP8은 성능과 현대화를 개선하기 위해 JIT 컴파일러 및 기타 기능을 소개합니다. 4) Opcache를 사용하고 PSR-12 표준을 따라 성능 및 코드 품질을 최적화하십시오.

PHP의 미래는 새로운 기술 트렌드에 적응하고 혁신적인 기능을 도입함으로써 달성 될 것입니다. 1) 클라우드 컴퓨팅, 컨테이너화 및 마이크로 서비스 아키텍처에 적응, Docker 및 Kubernetes 지원; 2) 성능 및 데이터 처리 효율을 향상시키기 위해 JIT 컴파일러 및 열거 유형을 도입합니다. 3) 지속적으로 성능을 최적화하고 모범 사례를 홍보합니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

Dreamweaver Mac版
시각적 웹 개발 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구
