PHPackages                             code4nix/uri-signer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. code4nix/uri-signer

ActiveSymfony-bundle[Security](/categories/security)

code4nix/uri-signer
===================

uri signer with expiration option

1.0.6(2y ago)14.4k↑54.5%2GPL-3.0-or-laterPHPPHP ^8.2

Since Feb 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/code4nix/uri-signer)[ Packagist](https://packagist.org/packages/code4nix/uri-signer)[ RSS](/packages/code4nix-uri-signer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (11)Used By (2)

URI Signer with expiration support for Symfony framework
========================================================

[](#uri-signer-with-expiration-support-for-symfony-framework)

Create and check signed URIs with expiration time support. This bundle is a further development of Symfony's [URI Signer](https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/HttpFoundation/UriSigner.php).

Installation
------------

[](#installation)

```
composer require code4nix/uri-signer

```

Usage
-----

[](#usage)

### Create a signed URI

[](#create-a-signed-uri)

To create a signed URI with an expiration time of 1 day (default), you can use `$this->uriSigner->sign($strUri)`. You can add a second parameter `$intExpires` to add a custom expiration time. E.g. call `$this->uriSigner->sign($strUri, 600)` to get a URI with an expiration time of 10 minutes.

### Check the signed URI/request

[](#check-the-signed-urirequest)

To check the URI you can use `$this->uriSigner->check($strUri)`.

Instead of building a URI you can call `$this->uriSigner->checkRequest($request)` method and pass a `Symfony\Component\HttpFoundation\Request` object to check the signature of its related URI. Both methods return boolean `true` if the URI passes validation, or boolean `false` if the URI is invalid or expired.

### Error handling

[](#error-handling)

Alternatively you can run the `check()` or `checkRequest()` methods with a second optional boolean parameter `$this->uriSigner->check($strUri, true)` or `$this->uriSigner->checkRequest($request, true)`, which will raise exceptions if a URI cannot be verified (e.g. has been tampered, has expired or is a malformed URI).

- `MalformedUriException`
- `InvalidSignatureException`
- `ExpiredLinkException`

Usage in your controller:
-------------------------

[](#usage-in-your-controller)

```
