A PC/SC extension for PHP
About
This is an unofficial extension for using PC/SC based smart cards with PHP. It is a wrapper to the wonderfull and free project PCSC-Lite which is the middleware to access a smart card using SCard API (PC/SC). Since PCSC-Lite is compatible to the winscard API it should be possible to compile this extension using a Windows(R) operating system. Currently I only take focus on Linux environments.
Thanks are going to Johann Dantant! He provides a PC/SC extension for PHP since 2005 and I reused some of his code. He allowed me to relicense these parts under the terms of the PHP license so I could integrate PCSC-Lite natively into PHP. You find his work here.
Status
This project is currently a work in progress and not ready for a release. I am working very hard to get stuff working properly and I will release the code when it becomes usable.
API
The extension currently provides the following API:
SCardEstablishContext();
Returns the application $context to the PC/SC resource manager.
SCardIsValidContext($context);
Returns TRUE if $context is valid or FALSE if $context is not valid.
SCardListReaders($context);
Returns an array of available readers or FALSE.
Example:
array(3) {
[0]=>
string(26) "OMNIKEY CardMan 5x21 00 00"
[1]=>
string(26) "OMNIKEY CardMan 5x21 00 01"
[2]=>
string(76) "SCL01x Contactless Reader [SCL01x Contactless Reader] (21161009200722) 00 00"
}
SCardConnect($context, "OMNIKEY CardMan 5x21 00 00");
Returns the $connection to a reader or FALSE.
SCardReconnect($connection);
Returns the $connection to a reader or FALSE.
SCardTransmit($connection, $apdu);
Returns the response $apdu as string or FALSE.
SCardStatus($connection);
Returns the status or FALSE.
SCardCancel($context);
SCardDisconnect($connection, SCARD_EJECT_CARD);
Disconnects the $connection to a card.
SCardReleaseContext($context);
Releases the application $context.
License
This code will be released under the terms of the PHP License version 3.01. PCSC-Lite is licensed in a way where it is possible to integrate it native in the PHP environment.
Links
- PC/SC Worgroup - Homepage and definition file downloads.
- PC/SC - At Wikipedia.
- PC/SC-Lite - The free and open implementation of the PC/SC SCard API for UNIX
- SCardSCR - Johann Dantant's implementation of a PC/SC extension for PHP
Comments
Please enter your comment here:
Previous comments:
$Date: 2010-08-10 21:42:35 +0200 (Tue, 10 Aug 2010) $
2010.08.23 - 01:32:33 - 1337
Looks like a simple very simple implementation of the API. :) Just waiting for the code! Please inform me when it is available.
2010.08.10 - 20:43:14 - Anonymous
Jep, exactly what I was looking for... where can I get the code? Please contact me!