Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'db.php';
- function url_exist($url)
- {
- $c=curl_init();
- curl_setopt($c,CURLOPT_URL,$url);
- curl_setopt($c,CURLOPT_HEADER,1);
- curl_setopt($c,CURLOPT_NOBODY,1);
- curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
- if(!curl_exec($c)){
- return false;
- }else{
- return true;
- }
- }
- function checarUrl($url) {
- $parseUrl = parse_url(trim($url));
- $dominio = $parseUrl['host'];
- return $dominio == "www.frhub.ga" || $dominio == "frhub.ga";
- }
- function shorteURLFromID ($integer)
- {
- $base = '0123456789abcdefghijklmnopqrstuvwxyz';
- $length = strlen($base);
- while($integer > $length - 5)
- {
- $out = $base[fmod($integer, $length)] . $out;
- $integer = floor( $integer / $length );
- }
- return $base[$integer] . $out;
- }
- if(isset($_POST['url']))
- {
- $url = trim(strip_tags($_POST['url']));
- $url = str_replace(array("http://", "http://www.", "www."), array('', '', ''), $url);
- if(strlen($url) < 3) die("Coloque uma URL");
- if(url_exist($url))
- {
- //check if exists
- $rs = mysql_query("SELECT string FROM links WHERE destination = '".mysql_real_escape_string($url)."'");
- if(@mysql_num_rows($rs)) {
- $row=@mysql_fetch_object($rs);
- $string = $row->string;
- print "http://".$_SERVER['SERVER_NAME']."/".$string;
- }else{
- if (checarUrl($_POST['url'])) {
- die("Coloque uma URL válida!");
- exit;
- }
- $rs = mysql_query("INSERT INTO links (destination, added, ip) VALUES
- ('".mysql_real_escape_string($url)."', '".time()."', '".ip2long($_SERVER['REMOTE_ADDR'])."')");
- if($rs) {
- $string = shorteURLFromID(mysql_insert_id());
- $rs = mysql_query("UPDATE links SET string = '$string' WHERE linkID = '".mysql_insert_id()."'");
- print "http://".$_SERVER['SERVER_NAME']."/".$string;
- }else{
- print "Não foi possivel encurtar este link.".mysql_error();
- }
- }
- }else{
- print "URL ínvalida!";
- }
- }else{
- print 'URL não recebida<br/>';
- }
Advertisement
Add Comment
Please, Sign In to add comment