mingalevme / utils-secure-link
Signing Url
Installs: 2 518
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
- mingalevme/http-build-url: ^1.0
Requires (Dev)
- phpunit/phpunit: ~6.0
This package is auto-updated.
Last update: 2024-11-08 02:07:32 UTC
README
Simple HMAC implementation with TTL support for public urls
Travis CI
Codecov
Installation
-
composer require mingalevme/utils-secure-link
. -
Now you are able to use the tool:
<?php const SECRET = 'YOUR_SECRET_KEY'; use Mingalevme\Utils\Url\SecureLink; $signer1 = new SecureLink(SECRET); echo $signer1->sign('https://github.com/mingalevme/secure-link-php'); // https://github.com/mingalevme/secure-link-php?signature=13-dGaz-frzJ9qUg3iQ0RA%3D%3D echo $signer1->sign('https://github.com/mingalevme/secure-link-php', 3600); // https://github.com/mingalevme/secure-link-php?expires=1526392953&signature=GOzCrktWlWDvSWVH49qjUQ%3D%3D $signer2 = new SecureLink(SECRET, [ 'signatureArgName' => '_sig', 'expiresArgName' => '_expires', ]); echo $signer2->sign('https://github.com/mingalevme/secure-link-php', 3600); // https://github.com/mingalevme/secure-link-php?_expires=1526393056&_sig=biyetWW5IgBPUftLF1SaOw%3D%3D
And validation
<?php const SECRET = 'YOUR_SECRET_KEY'; use Mingalevme\Utils\Url\SecureLink; $signer1 = new SecureLink(SECRET); if (!$signer1->isValid('https://github.com/mingalevme/secure-link-php?_expires=1526393056&_sig=biyetWW5IgBPUftLF1SaOw%3D%3D')) { throw new Exception('Url is invalid or expired'); }