ホームページ  >  記事  >  php教程  >  PHP は DB なしで短縮 URL オープンソース API を実装します

PHP は DB なしで短縮 URL オープンソース API を実装します

WBOY
WBOYオリジナル
2016-06-21 08:51:281119ブラウズ

設定ファイル

/*URL 設定*/

define(SITE,"http://xxx.com");//ドメイン名の後に /

を追加しないでください

/*API 設定*/

define(API_KEY,"");//API、アプリケーションアドレス: http://qita.in/reg.php

/*詳細設定*/

define(OPEN_AD,"0");//ジャンプページ広告スイッチ、1はオン、0はオフを意味します。

定義(AD,"私は広告です");//広告コンテンツ。二重引用符で囲まれたコンテンツには一重引用符のみを含める必要があります

define(TIME,"3");//ジャンプ待ち時間

?>

メインコード

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();

$タイムアウト = 5

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

//次の 2 行をユーザー検出が必要な Web ページに追加する必要があります

//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);

カール_クローズ($ch);

if(strlen($contents) $shorturl="正しい短縮 URL を入力してください";

}

$shorturl=SITE."/$new[1]";

//echo "[統計]";

//echo '';

}

?>

<頭>

PHP100.com の無料ショートアドレス

<スタイル>

a:link {color:#666;}

a:visited {テキスト装飾: なし;色: #333;}

a:hover {テキスト装飾: なし;

カラー: #333;}

a:active {テキスト装飾: なし;色: #CCC;}

body{margin:0px;background:url(bg_body.jpg)repeat-x;height:100%;text-align:center;}

.warp{margin:0 auto;width:620px;}img{border:none;}.c{clear:both;}.l{float:left;}.r{float:right;}ul,li{list-スタイル:なし;} .main{margin:0 auto;width:620px;}

.logo{margin:20px auto;text-align:center;}

.logo{font-size:50px}

.main p{text-align:center;color:#999;font-size:14px;}

.area{パディング:10px;背景:#f1f7f8;ボーダー:1px ソリッド #cfe0e0;}

.text_are{float:left;width:440px;height:36px;padding:5px 0;border:1px Solid #c6c6c6;font-size:16px;background:#ffffe6;}

.text_btn{float:left;margin-top:-1px;width:86px;height:36px;border:1px ソリッド #c6c6c6;background:#f8f8f8;}

.list{float:left;margin-top:-1px;padding:9px;border:1px Solid #cfe0e0;background:#FFF;font-size:12px;color:#999;}

.list td{パディング:3px 5px;ボーダーボトム:1px ソリッド #e1edef;高さ:30px;}

.more a{color:#333;text-decoration:none;}

.footer{margin-top:15px;font-size:11px;color:#CCC;text-align:center;}