PHP Classes

PHP One Time URL: Generate URL that only works one time for the user

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 41%Total: 643 All time: 4,970 This week: 146Up
Version License PHP version Categories
one-time-url 1GNU General Publi...5.0HTTP, PHP 5, Security


This class can generate URL that only works one time for the user.

It takes a given URL and stores it in session variables.

The class returns an obfuscated URL using a random key generated by the class that is also stored in session variables.

It can also retrieve the URL retrieving its key from the current request URL.

The class removes the URL and keys from the session variables, so the one time URL does not work anymore.

Applications should redirect the user to the real page URL when the user accesses the one time URL page.

Innovation Award
PHP Programming Innovation award nominee
March 2016
Number 3

Prize: One downloadable e-book of choice by O'Reilly
Some applications have the need to hide real URLs of resources that they link from their Web pages, so only users can access those resources.

This class can generate URLs that only work one time for the user that accessed a given page.

It uses sessions to store hidden URLs. Those URLs are associated with a key, so when a user accesses the page using a URL with a given key, he is redirected to the real URL. After that the key becomes invalid, so nobody else can use that key again.

Manuel Lemos
Picture of Dan From
Name: Dan From <contact>
Classes: 2 packages by
Country: Denmark Denmark
Age: 42
All time rank: 203415 in Denmark Denmark
Week rank: 354 Up2 in Denmark Denmark Up
Innovation award
Innovation award
Nominee: 1x



$onUrl = OTU::getOnUrl(); // Splits by ? on REQUEST_URI and returns the first part.
$realUrl = OTU::getRealUrl($onUrl); // Returns the real url, if valid.
$url = '/url/that/needs/to/be/hidden'; // The url that needs to be hidden
$obs = OTU::getObfuscatedUrl($url); // The obfuscated url

echo "Currently on: {$realUrl} <br />";
"<a href=\"{$obs}\">Link</a><br /><br />";

if (!
is_null($realUrl)) {
"Reloads in 3 seconds";
'<script>window.setTimeout(function() {location.reload();}, 3000);</script>';

  Files folder image Files  
File Role Description
Accessible without login Plain text file .htaccess Data .htaccess
Plain text file class.otu.php Class Main class
Accessible without login Plain text file index.php Example example

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:4,970
This week:146Up
 User Ratings  
 All time