Example #1
0
<?php

error_reporting(E_ALL);
//sends errors
require_once 'shortener.php';
//uses page data
$start = new Shortener();
//calls function
//if set, send link
if (isset($_POST['url'])) {
    //sets to url
    $url = $_POST['url'];
    //if code = function url, creates link
    if ($code = $start->makeURL($url)) {
        //Returns link short link
        $_SESSION['sendURL'] = "<a href=\"http://www.gcdsrv.com/~frw/link.php?code={$code}\">gcdsrv.com/~frw/link.php?code={$code}</a>";
    } else {
        $_SESSION['sendURL'] = "Invalid URL !!";
    }
}
//returns to main page
header('Location:page.php');
Example #2
0
<?php

require_once 'shortener.php';
if (isset($_GET['code'])) {
    $s = new Shortener();
    $code = $_GET['code'];
    if ($url = $s->getUrl($code)) {
        header("Location: {$url}");
        die;
    }
}
header('Location: index.php');
Example #3
0
<?php

error_reporting(E_ALL);
//reports errors
require_once 'shortener.php';
//uses database function
//if set, gets URL
if (isset($_GET['code'])) {
    //starts function
    $start = new Shortener();
    //sets code to = new_link
    $code = $_GET['code'];
    //gets related link; if old_link is related to new_link, send to old_link
    if ($url = $start->getUrl($code)) {
        //sets views
        mysql_query("UPDATE LINKS SET VIEWS = VIEWS +1 WHERE NEW_LINK = '{$code}'") or die(mysql_error());
        //redirects to site, using old_link
        header("Location: {$url}");
        die;
        //kills page
    }
}
//===ends if isset===
Example #4
0
<?php

session_start();
require_once 'classes/Shorterner.php';
$s = new Shortener();
if (isset($_POST['url'])) {
    $url = $_POST['url'];
    if ($code = $s->makeCode($url)) {
        $_SESSION['feedback'] = "Generated! Your Short URL is: <a href=\"http://localhost/urlshortner/{$code}\">http://localhost/urlshortner/{$code}</a>";
    } else {
        $_SESSION['feedback'] = "There was a Problem. Invalid URL.";
    }
}
header('Location: index.php');
Example #5
0
 /**
  * Rewrite URLs
  * 
  * @param string  $input   HTML string
  * @param boolean $shorten Shorten all URLs
  * @return string HTML string
  */
 public static function shorten($input = '', $shorten = false)
 {
     $rw = new Shortener($input);
     return $rw->shortenURLs();
 }