");
$input = mysql_real_escape_string($input);
return $input;
}
function prepOutputText($text) { // Takes mysql string and makes it able to be used
if ($text == null) die("No Input Provided, Aborting\r\n
");
$output = htmlentities(stripslashes($text),ENT_QUOTES);
return $output;
}
function checkRemoteFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE){
return true;
}else{
return false;
}
}
if(isset($_GET['l'])) { // if there is a link...
$l = $_GET['l']; // Bring the link into a variable
$l = input($l); // Clean said variable to be used in mysql
$sql = "SELECT id, link, shortlink FROM $tbl_name WHERE shortlink='$l'"; // Find the link in the table
$result = mysql_query($sql); // mysql stuff
$count = mysql_num_rows($result); // How many rows were found?
if($count == 1){ // There should only be one row
while ($row = mysql_fetch_assoc($result)){ // Start pulling data from the row
$id = $row['id']; // Lets get the id - not used, just a number used to identify the link or something, it's unique
$link = $row['link']; // This is the full link
$short = $row['shortlink']; // This is the short link - Should be a unique number
mysql_close(); // close the mysql connection
echo "Redirecting you to your site, please wait..."; // never seen
$link = prepOutputText($link); // make the link work
header("location:".$link); // redirect right away
}
}else{
echo "Hmmm... It appears that your link doesn't exist in my database. Try again?"; // not seen
header("location:http://unps.us/"); // redirect right away
}
}
?>
All you gotta do is put a link into the box and click submit
Here's the link: http://unps.us/?l=$short"; // Return link that's already in table } }else{ // If no row is returned, it is assumed that the link isn't there if(checkRemoteFile($dest) !== true) die("Hmmm it seems that your link is dead.\r\nPlease try again"); // Check to see if the host is alive $short = substr(number_format(time() * rand(),0,'',''),0,10); // Create a random number 10 digits long $short = base_convert($short, 10, 36); // Convert the 10 digit random number into Base36 $sql="INSERT INTO $tbl_name (link, shortlink) VALUES ('$dest', '$short')"; // Try to add the link and short link into table $result=mysql_query($sql); // mysql stuff if($result){ // If the link is added to the table echo "It appears that I have succeded in making a short link.Sorry, you are not able to shorten something without a url