tleckie / url-signer
使用php创建有限生命周期的安全URL
1.0.2
2021-04-26 13:52 UTC
Requires
- php: ^8
- httpsoft/http-message: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: v3.0.0-beta.2
- infection/infection: ^0.21.5
- phpunit/phpunit: ^9.5
README
使用php创建有限生命周期的安全URL
安装
您可以通过composer安装此包
composer require tleckie/url-signer
使用
<?php use Tleckie\UrlSigner\Exception\UnsignedException; use Tleckie\UrlSigner\Exception\ExpiredUriException; use Tleckie\UrlSigner\Signer; // sign with expiration $signer = new Signer('password', 'signature','ttl',3600); $signed = $signer->sign('https://www.domain.com/path/?query=value'); // https://www.domain.com/path/?query=value&ttl=1619446592&signature=b42cb0868c6c46aad10d2a5f6e3c6503cd6b9668 try{ $signer->validate($signed); }catch(ExpiredUriException $exception){ // handle expired uri }catch(UnsignedException $exception){ // Decrypt failed } // sign without expiration $signer = new Signer('password', 'signature'); $signed = $signer->sign('https://www.domain.com/path/?query=value'); // https://www.domain.com/path/?query=value&signature=e39fe2feea843712dc2b3fa069a50c6965594f5b