PHP code example of nazamey / zktecodevices

1. Go to this page and download the library: Download nazamey/zktecodevices 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/ */

    

nazamey / zktecodevices example snippets



Nazamey\Zktecodevices\ZKTecoDeviceManager;

// Initialize connection
$zk = new ZKTecoDeviceManager('192.168.1.100', 4370, 0, 'auto');

try {
    // Test connection
    $zk->testConnection();
    
    // Get device information (if your abstraction exposes it)
    $deviceInfo = $zk->getDeviceInfo();
    
    // Extract users
    $users = $zk->getUsers();
    
    // Extract attendance records
    $attendance = $zk->getAttendanceLogs();
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}


use Nazamey\Zktecodevices\ZKTecoDeviceManager;

$device_ip = "192.168.1.100";
$password = 0; // Device password (0 = no password)

$zk = new ZKTecoDeviceManager($device_ip, 4370, $password, 'auto');

// Example: extract all data in your preferred format
$users      = $zk->getUsers();
$attendance = $zk->getAttendanceLogs();

// Persist them as needed (CSV/JSON/DB/etc.)

[
    'uid' => 1,                    // User ID
    'user_id' => '1001',          // Badge number
    'name' => 'John Doe',         // User name
    'privilege' => 14,            // User privilege level
    'password' => '',             // User password
    'group_id' => 1,             // Group ID
    'card' => 0                  // Card number
]

[
    'uid' => 1,                           // User ID
    'user_id' => '1001',                 // Badge number  
    'timestamp' => '2025-10-22 09:15:30', // Date and time
    'status' => 1,                       // Check-in/out status
    'punch' => 1,                        // Punch type
    'date' => '2025-10-22',             // Date only
    'time' => '09:15:30'                // Time only
]

// Basic configuration
$device_ip = "192.168.1.100";    // Device IP address
$port = 4370;                    // Default ZKTeco port
$timeout = 60;                   // Connection timeout (seconds)
$password = 0;                   // Device password (0 = no password)

$zk = new Nazamey\Zktecodevices\ZKTecoDeviceManager($device_ip, $port, $password, 'auto');

$passwords = [0, 123456, 88888]; // Try multiple passwords

foreach ($passwords as $password) {
    $zk = new Nazamey\Zktecodevices\ZKTecoDeviceManager($device_ip, 4370, $password, 'auto');
    try {
        $zk->testConnection();
        echo "✅ Connected with password: $password\n";
        break;
    } catch (Exception $e) {
        echo "❌ Failed with password: $password\n";
    }
}