PHP code example of ikarus / sps-mfrc522

1. Go to this page and download the library: Download ikarus/sps-mfrc522 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ikarus / sps-mfrc522 example snippets



use Ikarus\MiFare\Authentication\BasicAuthentication;
use Ikarus\MiFare\Joyit\MFRC522_SPI;
use Ikarus\MiFare\Sector\MutableCardSector;
use Ikarus\Raspberry\Pinout\Revision_3\DynamicBCMPinout;
use Ikarus\Raspberry\RaspberryPiDevice;
use TASoft\Bus\SPI;

$dev = RaspberryPiDevice::getDevice();
$dev->($id) {
	$sector = new MutableCardSector(
	    MutableCardSector::SECTOR_ID_02,
	    BasicAuthentication::defaultAuthentication() // Key A: 0xFFFFFFFFFFFF
	);
	$sensor->readCardSector($id, $sector);

	print_r($sector);
} else
	echo "No tag detected.", PHP_EOL;



use Ikarus\MiFare\Authentication\BasicAuthentication;
use Ikarus\MiFare\Joyit\MFRC522_SPI;
use Ikarus\MiFare\Sector\CardSector;
use Ikarus\MiFare\Sector\MutableCardSector;
use Ikarus\Raspberry\Pinout\Revision_3\DynamicBCMPinout;
use Ikarus\Raspberry\RaspberryPiDevice;
use TASoft\Bus\SPI;

$dev = RaspberryPiDevice::getDevice();
$dev-> a card or badge near the sensor.", PHP_EOL;
$id = $sensor->readCardID(3);
echo "TAG: $id\n";

if($id) {
	$sector = new CardSector(
	    CardSector::SECTOR_ID_02,
	    $string,
	    BasicAuthentication::defaultAuthentication()
	);
	$sensor->writeCardSector($id, $sector);

	echo "OK, WRITTEN. VERIFY NOW ...\n";
	usleep(100000);
	
	$sector = new MutableCardSector(
	    MutableCardSector::SECTOR_ID_02,
	    BasicAuthentication::defaultAuthentication() // Key A: 0xFFFFFFFFFFFF
	);
	
	$id = $sensor->readCardID(3);
	$sensor->readCardSector($id, $sector);

	print_r($sector);
} else
	echo "No tag detected.", PHP_EOL;



use Ikarus\MiFare\Authentication\AccessBits;
use Ikarus\MiFare\Authentication\AuthenticationContainer;
use Ikarus\MiFare\Authentication\BasicAuthentication;
use Ikarus\MiFare\Joyit\MFRC522_SPI;
use Ikarus\MiFare\Sector\CardSector;
use Ikarus\Raspberry\Pinout\Revision_3\DynamicBCMPinout;
use Ikarus\Raspberry\RaspberryPiDevice;
use TASoft\Bus\SPI;

$dev = RaspberryPiDevice::getDevice();
$dev->,0x86,0x86]),
			BasicAuthentication::B([0xFF, 0x1, 0x2, 0x3, 0x4, 0x5])
		],
		new AccessBits([
		    AccessBits::C000, // Data Block 0
		    AccessBits::C000, // Data Block 1
		    AccessBits::C000, // Data Block 2
		    AccessBits::C001, // Trailer Block
		    0x0               // custom data byte
        ])
	);

	$sensor->writeAuthentication(
		$id,
		$auth,
		new CardSector(CardSector::SECTOR_ID_02, "", BasicAuthentication::A([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]))
	);
} else
	echo "No tag detected.", PHP_EOL;