url-signer
Create secured URLs with a limited lifetime in php
Installation
You can install the package via composer:
composer require tleckie/url-signer
Usage
<?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