PHP Classes

PHP Short URL Generator: Create short URLs storing them in a XML database

Recommend this page to a friend!
  Info   View files Example   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 260 All time: 7,794 This week: 107Up
Version License PHP version Categories
shorturl 1.0.0The PHP License5HTTP, PHP 5, Databases
Description 

Author

This package can be used to create short URLs storing them in a XML database.

It can take a given URL and associates it to short key string that can be used as the base of a short URL.

The package can also take the short key string and returns the associated long URL after finding it in the short URL XML database.

Each access to find the long URL of a given short URL string will increment an associated short URL hit counter for statistics purposes.

Innovation Award
PHP Programming Innovation award nominee
February 2020
Number 13
Short URLs are useful to provide a short version of an URL that may be too long to fit in certain Web forms that limit the length that the URL can have.

This package provides a complete solution to create short URLs that can be run on any domain that you control. It uses XML files to store the short URL information instead of regular SQL based databases.

Manuel Lemos
Picture of Chouchen
  Performance   Level  
Name: Chouchen <contact>
Classes: 5 packages by
Country: France France
Age: ???
All time rank: 259770 in France France
Week rank: 91 Up5 in France France Up
Innovation award
Innovation award
Nominee: 3x

Winner: 2x

Example

<?
/**
 *
 * Saving file
 * Take name and url, check if name already in base, and save
 */
session_start();
include
'class/ShortURL.php';

$url = new ShortURL();
$log = new Log('shorting.log');

$newname = $_POST['shortName'];
$newURL = $_POST['url'];

$log->message('entering '.$newname.' as '.$newURL);

$URI = $_SERVER['REQUEST_URI'];
$folders = explode('/', $URI);
if(
count($folders) > 2){
   
$folder = '/'.$folders[1].'/';
}else
   
$folder = '/';
$log->message('folder : '.$folder);

$_SESSION['msg'] = '';
if(
$newname =='' || $newURL==''){
   
$_SESSION['msg'] .= ShortURL::STATE_FIELD_MISSING;
   
$log->error(ShortURL::STATE_FIELD_MISSING);
}else{

   
$ret = $url->shortThisUrl($newURL, $newname);

    if(
is_bool($ret) && !$ret){
       
$log->error(ShortURL::STATE_FIELD_MISSING);
       
$_SESSION['msg'] .= ShortURL::STATE_FIELD_MISSING;
    }
    elseif(
$ret === ShortURL::STATE_ALREADY_EXIST){
       
$log->error(ShortURL::STATE_ALREADY_EXIST);
       
$_SESSION['msg'] .= $ret;
    }
    else{
       
$_SESSION['msg'] .= ShortURL::STATE_CREATED.': <a href="http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'">http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'</a>';
   
       
$log->message('that makes the link : http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'"');
    }
}
$log->message('Redirecting to '.$folder);
header('Location: '.$folder);


  Files folder image Files  
File Role Description
Files folder imageclass (3 files)
Files folder imagedb (3 files)
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login HTML file 404.html Doc. Documentation
Accessible without login Plain text file add.php Example Example script
Accessible without login Plain text file asecretpassage.php Example Example script
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file redir.php Example Example script
Accessible without login Plain text file short.php Example Example script

  Files folder image Files  /  class  
File Role Description
  Plain text file log.php Class Class source
  Plain text file ShortURL.php Class Class source
  Plain text file XMLSQL.php Class Class source

  Files folder image Files  /  db  
File Role Description
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file config.inc.php Aux. Auxiliary script
  Accessible without login Plain text file database.xml Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:260
This week:0
All time:7,794
This week:107Up