search
Homephp教程php手册PHP实现短网址开源API 不需要数据库

PHP实现短网址开源API 不需要数据库

Jun 13, 2016 am 10:51 AM
apidefinehttpphpxaccomplishOpen sourcedatabaseshortURLset upConfiguration file

[php] 
配置文件 
[php] 
/*网址设置*/ 
define(SITE,"http://xxx.com");//域名后面不要加/ 
/*API设置*/ 
define(API_KEY,"");//API,申请地址:http://qita.in/reg.php 
/*高级设置*/ 
define(OPEN_AD,"0");//跳转页广告开关,1表示开,0表示关. 
define(AD,"我是广告");//广告内容,双引号里内容必须只能包含单引号 
define(TIME,"3");//跳转等待时间 
?> 


主要代码


[php] 
require_once('config.inc.php'); 
if(API_KEY==""){ 
echo "请修改config.inc.php API_KEY参数,点击注册申请API"; 

if(count($_GET['url'])>0){ 
//$url = "http://1dnet.net/index.php?api=1&return_url_text=1&longUrl=".$_GET['url'];  
$url="http://qita.in/app.php?api=".API_KEY."&type=noad&url=".$_GET['url'];  
$ch = curl_init();  
$timeout = 5;  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
//在需要用户检测的网页里需要增加下面两行  
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);  
//curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD);  
$contents = curl_exec($ch);  
eregi('http://qita.in/(.*)',$contents,$new); 
curl_close($ch);  
if(strlen($contents) $shorturl="请输入正确的短网址"; 

$shorturl=SITE."/$new[1]"; 
//echo "[统计]"; 
//echo '';  

?> 
 
 

 
 
7898.org免费短地址 
 
 
 
 
 
 
 
 
      
       

缩短、分享及监测你的链接 

 
       
 
           
 
               
 
                 
 
               
 
               
 
           
 
           
 
                     
                         
     
     
 
 
'; 
echo ''; 
?> 
 
       
短链接原始网址
 
echo ''.$shorturl.'
'.$_GET['url'].'
 
         
 
           
 
  
           
 
       
 
 
  
 
 
 
 
 
 

 作者:liangxunli

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment