php NetEase free short address interface

WBOY
Release: 2016-07-25 09:06:42
Original
1376 people have browsed it
利用网易免费短地址接口开发的短网址缩短服务
演示地址: http://3.tbip.sinaapp.com/
伪静态规则
RewriteEngine on
RewriteRule ^(.*)$ index.php?id=$1 [L]
  1. define('REWRITE', '0'); //是否启用伪静态 1为启用0为不启用
  2. define('IS_SINA', '0'); //是否sina sae 1为启用0为不启用
  3. define('API_KEY', '2e409ff7a967418aa5e4dd15051702ba'); //API key请自行申请
  4. $weburl=getenv('SERVER_NAME').dirname(getenv('SCRIPT_NAME'));
  5. $weblink=REWRITE?"http://".$weburl."/":"http://".$weburl."/?";
  6. if($_GET['url']){
  7. $data=duanurl($_GET['url']);
  8. $shorturls=str_replace('126.am/',$weblink,$data->url);
  9. }else if(count($_GET)>0){
  10. $headurl=getenv("QUERY_STRING");echo "<script>location.href='http://126.am/".$headurl."'</script>";
  11. }
  12. ?>?
  13. 网易免费短地址
  14. 缩短、分享及监测你的链接

  • ';
  • echo '
  • ';
  • ?>
  • 短链接 原始网址
  • echo ''.$shorturls.'
  • '.$_GET['url'].'
  • <script>var bdShare_config = {"type":"large","color":"blue","uid":"533431","share":"yes"};</li> <li>document.getElementById("bdlike_shell").src="http://bdimg.share.baidu.com/static/js/like_shell.js?t=" + new Date().getHours();</li> <li></script>
  • 爱比特福
  • 比特福精品汇
  • IP查询
  • function ob_gzip($content){
  • if(!headers_sent()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")){
  • $content = gzencode($content,9);
  • header("Content-Encoding: gzip");
  • header("Vary: Accept-Encoding");
  • header("Content-Length: ".strlen($content));
  • }
  • return $content;
  • }
  • function duanurl($url)
  • {
  • if(IS_SINA){
  • $f = new SaeFetchurl();
  • $f->setMethod("post");
  • $f->setPostData(array("key"=>API_KEY,"longUrl"=>$url));
  • $content=$f->fetch("http://126.am/api!shorten.action");
  • if($f->errno() == 0) {
  • $return =$content;
  • }else{$return = $f->errmsg();}
  • }else{
  • $ch=curl_init();
  • curl_setopt_array(
  • $ch,
  • array(
  • CURLOPT_URL=>'http://126.am/api!shorten.action',
  • CURLOPT_RETURNTRANSFER=>true,
  • CURLOPT_POST=>true,
  • CURLOPT_POSTFIELDS=>'key='.API_KEY.'&longUrl='.$url
  • ));
  • $content=curl_exec($ch);
  • if(curl_errno($ch)) $return=curl_error($ch);
  • else $return=$content;
  • curl_close($ch);
  • }return json_decode($return);
  • }ob_end_flush(); ?>
  • 复制代码


    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!