tinyurl是国外一个短网址平台,功能与其他短网址平台功能一样,就是提供生成临时短网址的功能,无需注册游客即可生成短网址,为了方便,蓝叶分享自动生成短网址的php代码,使用此php代码只要传递网址过去,就可以实现tinyurl短网址自动生成代码,具体代码如下:
<?php /* * tinyurl自动生成代码 * author:蓝叶 * url:lanye.org */ $url = isset($_GET['url']) ? addslashes(trim($_GET['url'])) : 'https://lanye.org'; $tinyurl = GetTiny($url); echo $tinyurl; function GetTiny($url){ $headers = array( "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36", ); $curl = curl_init(); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_URL, 'https://tinyurl.com/api-create.php?url='.$url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $response = curl_exec($curl); curl_close($curl); return $response; }
免责声明:
本页网址:点击复制分享给朋友吧!
本站分享的一切内容资源如若没有备注,均为蓝叶原创,如需转载请注明出处;如有侵权请与我们联系处理。敬请谅解!