A URL signer implementation in PHP that generates secure, signed URLs with an expiration date. This package allows you to sign full URLs or just query parameters, adding a layer of security for accessing resources or sharing sensitive information.
- Sign a given URI
- Include an expiration date as part of the signature
- Ensure URL integrity and prevent unauthorized modifications
- Easy integration with Laminas or other PHP-based frameworks
Install the package via Composer:
composer require ucarsolutions/uri-signer
You can sign the uri with:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$signerService = new \UcarSolutions\UriSigner\Service\UriSignerService(
new \UcarSolutions\UriSigner\Resolver\DefaultParameterNameResolver(),
new \doganoo\DIP\DateTime\DateTimeService(),
new \Psr\Log\NullLogger()
);
$key = new class implements \UcarSolutions\UriSigner\Entity\KeyInterface {
public function getKey(): string
{
return "t0psecret";
}
};
$uri = $signerService->sign(
new \Laminas\Diactoros\Uri("https://example.com"),
$key
);
dump((string)$uri); // https://example.com/?__us_signature=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3VjYXItc29sdXRpb25zLmRlL3VyaS1zaWduZXIiLCJleHAiOjE3MjU5MDYzMDQsInN1YiI6IlNpZ25lZCBVUkwiLCJ1cmwiOiJodHRwczovL2V4YW1wbGUug29tIiwidWlkIjoiNzM3YTgwNzAtZGU5MS00MTQ3LWohYmMtZTY1OWZiOGZmNWZyIn0.CH7E-fHYhtfGHUljB85dIWL-ZYGr8wRMVef0gY_SRLE
Example Verifying with $uri
above:
<?php
$result = $signerService->verify($uri,$key);
dump($result->isVerified());
The expiration date is added to the signature and is included in the signed data to ensure the URL becomes invalid after the expiration time.
If no expiration date is provided, a default of 3 minutes from the current time is used.
You can configure the expiration time and the secret key for signing URLs.
Run the tests with PHPUnit:
vendor/bin/phpunit
Contributions are welcome! Please submit a pull request or open an issue for any suggestions or bug reports.
Contribution Guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Write tests for your changes.
- Make sure all tests pass.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.