An implementation of the PC/SC SCard API for PHP.
  • C 92.7%
  • PHP 3.8%
  • M4 3.5%
Find a file
2021-02-21 06:19:50 +01:00
docs/examples Fixed and added some more PHP test code; Not stable 2021-02-21 06:19:50 +01:00
.gitignore add common .gitignore rules 2021-02-10 10:22:52 +01:00
config.m4 fix header installation dir 2014-05-04 17:20:35 +00:00
config.w32 Fix compiler warnings, use zval resource instead of long for handles 2014-02-12 17:02:04 +00:00
COPYING Initial commit of the PC/SC (pcsc) extension. There is some stuff that needs to be romoved like the build.sh script and the subfolders tmp/ and php/. 2011-12-13 16:57:24 +00:00
CREDITS.md CREDITS name order fix 2021-02-21 03:10:30 +01:00
package.xml Converted documentaion files to Markdown; Updated all content to current version; Added some credit; 2021-02-21 01:34:32 +01:00
pcsc.c generate arginfo from stub file 2021-02-10 10:23:42 +01:00
pcsc.stub.php fix default valur 2021-02-10 11:04:17 +01:00
pcsc_arginfo.h fix default valur 2021-02-10 11:04:17 +01:00
pcsc_legacy_arginfo.h fix default valur 2021-02-10 11:04:17 +01:00
php_pcsc.h Converted documentaion files to Markdown; Updated all content to current version; Added some credit; 2021-02-21 01:34:32 +01:00
README.md API documentation fix. 2021-02-21 01:55:04 +01:00
TODO.md Converted documentaion files to Markdown; Updated all content to current version; Added some credit; 2021-02-21 01:34:32 +01:00

PC/SC for PHP

About

This is the only extension for using PC/SC based smart cards with PHP. It is a wrapper to the wonderful and free project by Ludovic Rousseau, 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 or macOS operating system.

Thanks are going to Johann Dantant! He provided 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 native into PHP.

Installation

I recommend to install the PECL extension the "PHP" way:

pecl install pcsc-beta

You can install the latest code by downloading the sources and compile yourself too.

git clone https://github.com/pcsc-for-php/pcsc.git
cd pcsc
phpize
./configure
make
make install

After that you have all needed files in ./modules/ .

API

The extension currently provides the following API:

scard_establish_context();

Returns the application $context to the PC/SC resource manager.

scard_is_valid_context($context);

Returns TRUE if $context is valid or FALSE if $context is not valid.

scard_release_context($context);

Releases the application $context.

scard_list_readers($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"
}

scard_connect($context, "OMNIKEY CardMan 5x21 00 00");

Connects to a card. Returns the $connection to a reader or FALSE.

scard_reconnect($connection);

Returns the $connection to a reader or FALSE.

scard_disconnect($connection);

Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE.

scard_transmit($connection, $apdu);

Returns the response $apdu as string or FALSE.

scard_status($connection);

Returns the status or FALSE.

scard_cancel($context);

License

This code is licensed 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.