利用网易免费短地址接口开发的短网址缩短服务
演示地址:
http://3.tbip.sinaapp.com/
伪静态规则
RewriteEngine on
RewriteRule ^(.*)$ index.php?id=$1 [L]
-
define('REWRITE', '0'); //是否启用伪静态 1为启用0为不启用
- define('IS_SINA', '0'); //是否sina sae 1为启用0为不启用
- define('API_KEY', '2e409ff7a967418aa5e4dd15051702ba'); //API key请自行申请
- $weburl=getenv('SERVER_NAME').dirname(getenv('SCRIPT_NAME'));
- $weblink=REWRITE?"http://".$weburl."/":"http://".$weburl."/?";
- if($_GET['url']){
- $data=duanurl($_GET['url']);
- $shorturls=str_replace('126.am/',$weblink,$data->url);
- }else if(count($_GET)>0){
- $headurl=getenv("QUERY_STRING");echo "<script>location.href='http://126.am/".$headurl."'</script>";
- }
- ?>?
-
-
- 网易免费短地址
-
-
-
- <script>var bdShare_config = {"type":"large","color":"blue","uid":"533431","share":"yes"};<li>document.getElementById("bdlike_shell").src="http://bdimg.share.baidu.com/static/js/like_shell.js?t=" + new Date().getHours();<li></script>
-
-
-
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(); ?>
复制代码
|
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31