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

Comments

Please enter your comment here:




Security check, please solve:

CY2         O        
G 6    9    G A   MXE
K G   X1E   3GM      
N 1    W      L   U9T
H7K           4      

Previous comments:

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!

$Date: 2010-08-10 21:42:35 +0200 (Tue, 10 Aug 2010) $