Sample code for 30+ languages & platforms
PHP

Verify a Zip's Password

See more Zip Examples

Demonstrates how to verify the password for an encrypted or password-protected zip archive.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Zip;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$zip = new Zip();

// To verify a password for a Zip, the Zip must be opened:
try {
    $zip->OpenZip('myProtected.zip');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Set the password to be verified:
$zip->DecryptPassword = 'secret';

$passwordOk = $zip->VerifyPassword();
if ($passwordOk) {
    echo "Password is correct.\n";
} else {
    echo "Password is incorrect.\n";
}

$zip->CloseZip();