PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of anas khan   Custom PHP URL Shortener using PDO   index.php   Download  
File: index.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: 2 years ago
Size: 826 bytes


Class file image Download
// 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);

// Long URL
$longURL = '';

// Prefix of the short URL
$shortURL_Prefix = ''; // with URL rewrite
$shortURL_Prefix = ''; // without URL rewrite

// Get short code of the URL
$shortCode = $shortener->urlToShortCode($longURL);
// Create short URL
$shortURL = $shortURL_Prefix.$shortCode;
// Display short URL
echo 'Short URL: '.$shortURL;
Exception $e){
// Display error
echo $e->getMessage();