PHPackages                             spatie/url-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. [Mail &amp; Notifications](/categories/mail)
4. /
5. spatie/url-signer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

spatie/url-signer
=================

Generate a url with an expiration date and signature to prevent unauthorized access

2.1.3(1y ago)4422.3M—0%50[1 PRs](https://github.com/spatie/url-signer/pulls)15MITPHPPHP ^8.1CI passing

Since Aug 14Pushed 1mo ago13 watchersCompare

[ Source](https://github.com/spatie/url-signer)[ Packagist](https://packagist.org/packages/spatie/url-signer)[ Docs](https://github.com/spatie/url-signer)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-url-signer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (18)Used By (15)

Create signed URLs with a limited lifetime
==========================================

[](#create-signed-urls-with-a-limited-lifetime)

[![Latest Version on Packagist](https://camo.githubusercontent.com/db6b13d01913345725e9849ba59d57cbcb0626872dfb62c3d77a66199ccaa161/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f75726c2d7369676e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/url-signer)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/65f846e4142a2ebd371404083668a988e26411801eef0be27fc21702a2efed2d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f75726c2d7369676e65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/url-signer)[![Total Downloads](https://camo.githubusercontent.com/6bf5d76e2e8caecd3e930526c04411e3dfcda3d7a71d2a375eff5f68e56f4977/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f75726c2d7369676e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/url-signer)

This package can create URLs with a limited lifetime. This is done by adding an expiration date and a signature to the URL.

```
$urlSigner = new Sha256UrlSigner('randomkey');

$urlSigner->sign('https://myapp.com', 30);

// => The generated url will be valid for 30 seconds
```

This will output a URL that looks like `https://myapp.com/?expires=xxxx&signature=xxxx`.

Imagine mailing this URL out to the users of your application. When a user clicks on a signed URL your application can validate it with:

```
// returns `true` if valid, `false` if not
$urlSigner->validate('https://myapp.com/?expires=xxxx&signature=xxxx');
```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/233a6c1607a123163129ea38732e9a9b1677f5eab47e888d58f8284ca1870a9d/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f75726c2d7369676e65722e6a70673f743d31)](https://spatie.be/github-ad-click/url-signer)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

All postcards are published [on our website](https://spatie.be/en/opensource/postcards).

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

[](#installation)

The package can installed via Composer:

```
composer require spatie/url-signer

```

Usage
-----

[](#usage)

A signer-object can sign URLs and validate signed URLs. A secret key is used to generate signatures.

```
use Spatie\UrlSigner\Sha256UrlSigner;

$urlSigner = new Sha256UrlSigner('mysecretkey');
```

### Generating URLs

[](#generating-urls)

Signed URLs can be generated by providing a regular URL and an expiration date to the `sign` method.

```
$expirationDate = (new DateTime())->modify('10 days');

$urlSigner->sign('https://myapp.com', $expirationDate);

// => The generated url will be valid for 10 days
```

If an integer is provided as expiration date, the URL will be valid for that amount of seconds.

```
$urlSigner->sign('https://myapp.com', 30);

// => The generated URL will be valid for 30 seconds
```

### Validating URLs

[](#validating-urls)

To validate a signed URL, simply call the `validate()` method. This will return a boolean.

```
$urlSigner->validate('https://myapp.com/?expires=1439223344&signature=a479abde194d111022a6831edbda29b14e7bdb760438a8a0be2556cd1a6c23fa');

// => true

$urlSigner->validate('https://myapp.com/?expires=1439223344&signature=a479abde194d111022a6831edbda-INVALID-29b14e7bdb760438a8a0be2556cd1a6c23fa');

// => false
```

Writing custom signers
----------------------

[](#writing-custom-signers)

This packages provides a signer that uses SHA256 to generate signature. You can create your own signer by implementing the `Spatie\UrlSigner\Contracts\UrlSigner`-interface. If you let your signer extend `Spatie\UrlSigner\AbstractUrlSigner` you'll only need to provide the `createSignature`-method.

Tests
-----

[](#tests)

The tests can be run with:

```
composer test

```

Integrations
------------

[](#integrations)

To get started quickly in Laravel you can use the [spatie/laravel-url-signer](https://github.com/spatie/laravel-url-signer) package.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance69

Regular maintenance activity

Popularity62

Solid adoption and visibility

Community38

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 50.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~247 days

Recently: every ~169 days

Total

15

Last Release

458d ago

Major Versions

1.2.3 → 2.0.02022-11-12

PHP version history (6 changes)1.0.0PHP &gt;=5.5.0

1.0.2PHP &gt;=5.6.0

1.1.0PHP ^7.2

1.2.0PHP ^7.2|^8.0

1.2.3PHP ^7.4|^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (90 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (19 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (12 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (8 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![arjanwestdorp](https://avatars.githubusercontent.com/u/7716654?v=4)](https://github.com/arjanwestdorp "arjanwestdorp (2 commits)")[![erikn69](https://avatars.githubusercontent.com/u/4933954?v=4)](https://github.com/erikn69 "erikn69 (2 commits)")[![juukie](https://avatars.githubusercontent.com/u/2678657?v=4)](https://github.com/juukie "juukie (1 commits)")[![kronthto](https://avatars.githubusercontent.com/u/17156142?v=4)](https://github.com/kronthto "kronthto (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![alanpoulain](https://avatars.githubusercontent.com/u/10920253?v=4)](https://github.com/alanpoulain "alanpoulain (1 commits)")[![debuqer](https://avatars.githubusercontent.com/u/24442370?v=4)](https://github.com/debuqer "debuqer (1 commits)")[![Chris8934](https://avatars.githubusercontent.com/u/44963939?v=4)](https://github.com/Chris8934 "Chris8934 (1 commits)")[![emmanuel-averty](https://avatars.githubusercontent.com/u/99648541?v=4)](https://github.com/emmanuel-averty "emmanuel-averty (1 commits)")[![alexbowers](https://avatars.githubusercontent.com/u/842974?v=4)](https://github.com/alexbowers "alexbowers (1 commits)")[![jakejackson1](https://avatars.githubusercontent.com/u/2918419?v=4)](https://github.com/jakejackson1 "jakejackson1 (1 commits)")

---

Tags

mailphpsecuritysignurlurlspatiesecurityencryptionsign

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatie-url-signer/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-url-signer/health.svg)](https://phpackages.com/packages/spatie-url-signer)
```

###  Alternatives

[spatie/laravel-failed-job-monitor

Get notified when a queued job fails

1.0k2.6M4](/packages/spatie-laravel-failed-job-monitor)[tilleuls/url-signer-bundle

Create and validate signed URLs with a limited lifetime in Symfony

81340.1k](/packages/tilleuls-url-signer-bundle)[spatie/laravel-url-signer

Laravel implementation of spatie/signed-url

717784.1k3](/packages/spatie-laravel-url-signer)[spatie/laravel-database-mail-templates

Render Laravel mailables using a template stored in the database.

446762.6k7](/packages/spatie-laravel-database-mail-templates)[nzo/url-encryptor-bundle

The NzoUrlEncryptorBundle is a Symfony Bundle used to Encrypt and Decrypt data and variables in the Web application or passed through URL

961.0M2](/packages/nzo-url-encryptor-bundle)[spatie/mjml-php

Convert MJML to HTML using PHP

272668.4k10](/packages/spatie-mjml-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
