Location: PHPKode > scripts > MiniUrl short URL dynamic > miniurl-short-url-dynamic/miniUrl.php
<?php
class miniUrl{

var $gets;
var $conexao;
var $vercode;
var $paste;
var $domain;
var $destiny;
var $diretory = "miniurl";

    function __construct(){
    $gets = explode("/",str_replace(strrchr($_SERVER["REQUEST_URI"], "?"), "", $_SERVER["REQUEST_URI"]));;
array_shift($gets);
    $this->gets = $gets;
    $this->dataConnect();
    }

    function dataConnect(){
        $conexao = mysql_pconnect('localhost', 'root', '') or die ('não conectou ao servidor');
        mysql_select_db("miniurl",$conexao) or die ('não conectou a tabela');
        $paste = "http://".$_SERVER['HTTP_HOST']."/".$this->diretory;
        $domain = "http://".$_SERVER['HTTP_HOST'];
        $this->conexao = $conexao;
        $this->paste = $paste;
        $this->domain = $domain;
    }

    function showAdress(){

    $adress = $this->paste."/".$this->vercode;
    return $adress;
    }
    function header(){
            $query = "SELECT url FROM adress WHERE cod = '".$_GET['code']."'";
            $query = mysql_query($query, $this->conexao)or die(mysql_error());
            $query = mysql_fetch_array($query);
            $destiny = 'http://'.$query[0];
            $this->destiny = $destiny;
    }
    function redirectPage(){
    		$query = "SELECT url FROM adress WHERE cod = '".$this->gets[1]."'";
            $query = mysql_query($query, $this->conexao)or die(mysql_error());
            $query = mysql_fetch_array($query);
            $destiny = 'http://'.$query[0];
            $this->destiny = $destiny;
            
    }
    function geraCod(){
        if (!isset($numofletters)) $numofletters = 15; // if $numofletters is not specified sets to 10 letters
        $literki = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' );
        $ilosc_literek = count($literki);
        for ($licz = 0; $licz < $numofletters; $licz++) {
        $rand = rand(0, $ilosc_literek-1);
        $vercode = $vercode.$literki[$rand];
        $this->vercode = $vercode;
    }
    }
    function create($url){
        $this->geraCod();
        $url = str_replace("http://", "", $url);
        $query = "INSERT INTO adress(cod, url) VALUES('$this->vercode','$url')";
        mysql_query($query, $this->conexao)or die(mysql_error());
    }

}
?>
Return current item: MiniUrl short URL dynamic