PHP Classes

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

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 41%Total: 645 All time: 4,960 This week: 47Up
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: 42
All time rank: 203415 in Denmark Denmark
Week rank: 215 Up2 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 (3)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:645
This week:0
All time:4,960
This week:47Up
 User Ratings  
 
 All time
Utility:60%StarStarStarStar
Consistency:55%StarStarStar
Documentation:-
Examples:55%StarStarStar
Tests:-
Videos:-
Overall:41%StarStarStar
Rank:3747