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: 642 All time: 4,968 This week: 90Up
Version License PHP version Categories
one-time-url 1GNU General Publi...5.0HTTP, PHP 5, Security
Description 

Author

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: 41
All time rank: 203315 in Denmark Denmark
Week rank: 312 Up3 in Denmark Denmark Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php
session_start
();
require_once
'class.otu.php';

$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 />";
echo
"<a href=\"{$obs}\">Link</a><br /><br />";

if (!
is_null($realUrl)) {
  echo
"Reloads in 3 seconds";
  echo
'<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  
 0%
Total:642
This week:0
All time:4,968
This week:90Up
 User Ratings  
 
 All time
Utility:60%StarStarStarStar
Consistency:55%StarStarStar
Documentation:-
Examples:55%StarStarStar
Tests:-
Videos:-
Overall:41%StarStarStar
Rank:3662