PHP code example of abovesky / url-auth

1. Go to this page and download the library: Download abovesky/url-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abovesky / url-auth example snippets


$urlAuth = new Md5('randomkey');

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

// => The generated url will be valid for 30 days

$urlAuth->validate('https://myapp.com/?expires=xxxx&signature=xxxx');

use abovesky\UrlAuth\Md5;

$urlAuth = new Md5('mysecretkey');

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

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

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

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

// => The generated url will be valid for 30 days

$urlAuth->validate('https://myapp.com/?expires=1439223344&signature=2d42f65bd023362c6b61f7432705d811');

// => true

$urlAuth->validate('https://myapp.com/?expires=1439223344&signature=2d42f65bd0-INVALID-23362c6b61f7432705d811');

// => false