include("config.php"); session_start(); if($_REQUEST['link']== "Enter a long URL to make small:"){ header("location:index.php"); }else{ if(isset($_POST['submit'])){ $site = str_replace("www.","",$_SERVER['SERVER_NAME']); if (isset($_REQUEST['link'])) { $link = $_REQUEST['link']; $alias = $_REQUEST['alias']; if (strstr($link,":") === false) { $link = "http://".$link; } $blnAliasNotfound=false; if(strlen($link)<=25){ function generateUniqueID() { global $connection; $token = substr(md5(uniqid(rand(), true)),0,3); // creates a 3 digit token $query = "SELECT code FROM tblmyurl WHERE code = '$token'"; $result = mysql_query($query); if (mysql_num_rows($result) !== 0) { generateUniqueID(); } else { return $token; } } } elseif(strlen($link)<=70){ function generateUniqueID() { global $connection; $token = substr(md5(uniqid(rand(), true)),0,4); // creates a 4 digit token $query = "SELECT code FROM tblmyurl WHERE code = '$token'"; $result = mysql_query($query); if (mysql_num_rows($result) !== 0) { generateUniqueID(); } else { return $token; } } } elseif(strlen($link)>=70){ function generateUniqueID() { global $connection; $token = substr(md5(uniqid(rand(), true)),0,5); // creates a 5 digit token $query = "SELECT code FROM tblmyurl WHERE code = '$token'"; $result = mysql_query($query); if (mysql_num_rows($result) !== 0) { generateUniqueID(); } else { return $token; } } } $code = generateUniqueID(); if ($alias!=""){ $sql="SELECT * FROM tblmyurl WHERE code='$alias'"; $resource = mysql_query($sql); $row = mysql_fetch_array($resource,MYSQL_NUM); if (mysql_num_rows($resource)>0){ $blnAliasNotfound=true; }else{ $code=$alias; } } $tinyurl = "http://".$site."/".$code; $sql="INSERT INTO tblmyurl (code,link) VALUES('$code','$link')"; $result = mysql_query($sql); } }else{ //header("location:index.php"); } } ?> $site = str_replace("www.","",$_SERVER['SERVER_NAME']); ?>
Get rid of long URLs and create a new short URLs.
If you are you facing the problem because of long URL then GomyURL has the best solution for your problem. GomyURL is a free service which creates small URL and hides the real URL from the visitors.
Just paste URL in the GomyURL box below and we will create a small URL which will not break in email postings and never expires.
"; if ($blnAliasNotfound==true){ echo "The custom alias you've chosen is not available. We've created a random one for you instead, but you can try assigning a different custom alias again below. Use 6 characters or more for the best chance of getting a unique unassigned alias."; } ?> The following URL:
$newlink = chunk_split($link,50,"
");
echo $newlink?>
echo $tinyurl;?>
[open new window]
echo "http://preview.".$site."/".$code;?>
" target="_blank"> [open new window]