Guest Alomax Postado Março 15, 2015 Denunciar Postado Março 15, 2015 No meu encurtador tem engraçadinhos encurtando URLS encurtadas e-e isso está bugando!!!!!!! :,c Então eu queria saber se tem um jeito de eu bloquear que eles possam fazer isto. Este é o codigo que cuida dos bloqueios e etc <?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 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{ $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/>'; } ?>
AlanGomes_ (BrineDev) Postado Março 15, 2015 Denunciar Postado Março 15, 2015 (editado) function checarUrl($url) { $parseUrl = parse_url(trim($Address)); $dominio = trim($parseUrl['host']) ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2)); return $dominio=="meudominio.com"; } Vai retornar true se for meudominio.com e false se não for. Editado Março 15, 2015 por BrineDev
AlanGomes_ (BrineDev) Postado Março 15, 2015 Denunciar Postado Março 15, 2015 (editado) Double post Editado Março 15, 2015 por BrineDev
Guest Alomax Postado Março 15, 2015 Denunciar Postado Março 15, 2015 Double post mas onde eu boto isso ? =/ não sei nada de php
AlanGomes_ (BrineDev) Postado Março 15, 2015 Denunciar Postado Março 15, 2015 (editado) mas onde eu boto isso ? =/ não sei nada de php Vou editar seu código, te mando jaja @EDIT: http://pastebin.com/vTh4bP8f Editado Março 15, 2015 por BrineDev
KroyBR Postado Março 15, 2015 Denunciar Postado Março 15, 2015 Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas. Atenciosamente, Gamer's Board
Pergunta
Guest Alomax
No meu encurtador tem engraçadinhos encurtando URLS encurtadas e-e isso está bugando!!!!!!! :,c
Então eu queria saber se tem um jeito de eu bloquear que eles possam fazer isto.
Este é o codigo que cuida dos bloqueios e etc
<?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 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{ $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/>'; } ?>5 respostass a esta questão
Posts Recomendados