Created
June 22, 2018 03:52
-
-
Save iDavidMorales/96c545d1fa180acb61656da853a52f62 to your computer and use it in GitHub Desktop.
Curl Shorte.St API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function shst($url){ | |
$apiurl="https://api.shorte.st/v1/data/url"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. | |
curl_setopt($ch, CURLOPT_URL, $apiurl); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT' ); | |
// Agregamos el Token que copiamos de la pagina. | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('public-api-token: XXXXXXXXXXXXXXXXXXX','X-HTTP-Method-Override: PUT')); | |
// Pasamos la bariable $url que queremos acortar. | |
curl_setopt($ch, CURLOPT_POSTFIELDS, "urlToShorten=".$url); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
$obj = json_decode($data); | |
// Obtenemos el enlace acortado ya de manera automatica. | |
$ret=$obj->{'shortenedUrl'}; | |
// Asignamos la direccion aun hipervinculo y listo. | |
echo'<a href="'.$ret.'" >Enlace con publicidad</a>'; | |
return $ret; | |
} | |
// Solo hace falta asignar la url que queremos acortar a la funcion | |
$url=$_GET['url']; | |
shst($url); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment