PHP Classes

File: redirect.php

Recommend this page to a friend!
  Classes of anas khan   Custom PHP URL Shortener using PDO   redirect.php   Download  
File: redirect.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Custom PHP URL Shortener using PDO
Create and expand short URLs in a custom domain
Author: By
Last change:
Date: 3 years ago
Size: 539 bytes
 

Contents

Class file image Download
<?php


// Include database configuration file
require_once 'config.php';

// Include URL Shortener library file
require_once 'class.URLShortner.php';

// Initialize Shortener class and pass PDO object
$shortener = new URLShortner($db);

// Retrieve short code from URL
$shortCode = $_GET["c"];

try{
   
// Get URL by short code
   
$url = $shortener->shortCodeToUrl($shortCode);
   
   
// Redirect to the original URL
   
header("Location: ".$url);
    exit;
}catch(
Exception $e){
   
// Display error
   
echo $e->getMessage();
}


?>