- Joined
- Apr 30, 2007
- Messages
- 2,339
- Reaction score
- 1,547
Hi.. I had a semi popular URL shortening website but as it's now offline I have no use for the script.
Features:
- Shortening URLs and providing the short url
- htaccess for dynamic short urls
- OOP PHP
- Simple yet elegant design
- Template system
Here is the shortening class for a taste of what is inside the download;
Download;
Have fun & good luck with php
Features:
- Shortening URLs and providing the short url
- htaccess for dynamic short urls
- OOP PHP
- Simple yet elegant design
- Template system
Here is the shortening class for a taste of what is inside the download;
Code:
<?php
class SoShort
{
public function ParseConfig()
{
require_once "inc/config.php";
$this->config = new Config;
}
public function AddURL($short_code, $full_url)
{
global $db;
$db->real_query("INSERT INTO `urls` (`original_url`, `short_code`, `active`) VALUES ('" . $full_url . "', '" . $short_code . "', '1')") or die($db->error);
}
public function IsAlreadyShortened($full_url)
{
global $db;
if($query = $db->query("SELECT `full_url` FROM `urls` WHERE `full_url` = '" . $full_url . "'"))
{
$num = $query->num_rows;
if($num > 0)
{
return true;
}
}
return false;
}
public function GetURLInfo($url, $info)
{
global $db;
if($query = $db->query("SELECT `" . $info . "` FROM `urls` WHERE `original_url` = '" . $url . "'"))
{
while($dRow = $query->fetch_row())
{
$data = $dRow[0];
}
return $data;
}
}
public function GenerateShortURL()
{
$strs = "1234567890asdfghjklqwertyuiopzxcvbnm";
$random = '';
for($i = 0; $i < 5; $i++)
{
$random .= $strs[mt_rand(0, strlen($strs) - 1)];
}
return $random;
}
public function IsAURL($url)
{
if(strpos($url, 'http://') !== false)
{
return true;
}
else if(strpos($url, 'https://') !== false)
{
return true;
}
return false;
}
public function GetFullFromShort($url)
{
global $db;
if($query = $db->query("SELECT `original_url` FROM `urls` WHERE `short_code` = '" . $url . "'"))
{
while($data = $query->fetch_assoc())
{
$return = $data['original_url'];
}
}
return $return;
}
public function DoesShortURLExist($url)
{
global $db;
if($query = $db->query("SELECT null FROM `urls` WHERE `short_code` = '" . $url . "'"))
{
$num = $query->num_rows;
if($num >= 1)
{
return true;
}
}
return false;
}
public function GetNumberOfURLs()
{
global $db;
if($query = $db->query("SELECT null FROM urls"))
{
return number_format($query->num_rows);
}
return 0;
}
}
?>
You must be registered to see links
Have fun & good luck with php