tleckie/url-signer

1.0.2 2021-04-26 13:52 UTC

This package is auto-updated.

Last update: 2024-03-11 13:42:17 UTC


README

Create secured URLs with a limited lifetime in php

Latest Version on Packagist Scrutinizer Code Quality Total Downloads Code Intelligence Status Build Status

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