PHP Classes

File: redirect.php

Recommend this page to a friend!
  Classes of Faris AL-Otabi   PHP URL Shortener   redirect.php   Download  
File: redirect.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP URL Shortener
Application to create and expand short URLs
Author: By
Last change:
Date: 11 months ago
Size: 818 bytes
 

Contents

Class file image Download
<?php

require_once 'config/config.php';

$db = new Framework\Database();

$shortener = new Framework\Shortener($db);

$utils = new Framework\Utils();

try {
   
$shortCode = rtrim($utils->sanitize($_GET["c"]), "/");

    if (
$shortener->is_protected($shortCode)) {
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
            if (
$shortener->checkPassword($shortCode, $utils->sanitize($_POST['password']))) {
               
$utils->redirect(
                   
$shortener->shortCodeToUrl($shortCode)
                );
            } else {
               
$msg = "Incorrect Password";
            }
        }
        include_once
'password_form.php';
    } else {
       
$utils->redirect(
           
$shortener->shortCodeToUrl($shortCode)
        );
    }
} catch (
Exception $e) {
    echo
$e->getMessage();
}