OSDN Git Service

embrj
[embrj/master.git] / ajax / expand.php
1 <?php
2
3 include_once('../lib/config.php');
4 include_once('../lib/twitese.php');
5
6 if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) != parse_url(BASE_URL, PHP_URL_HOST)) {
7         echo '{"error":"Invalid referer."}';
8         exit();
9 }
10
11 $url = isset($_GET['url']) ? $_GET['url'] : false;
12 if (!$url || empty($url)) {
13         echo '{"error":"No URL is provided."}';
14         exit();
15 }
16 if (!filter_var($url, FILTER_VALIDATE_URL)) {
17         echo '{"error":"Malformed URL."}';
18         exit();
19 }
20
21 $thehops = array();
22 $answer = expandRedirect($url, $thehops);
23 if (!$answer) {
24         echo '{"error":"No URL is provided."}';
25 }
26 else
27         echo "{\"expanded_url\":\"$answer\"}";
28
29 ?>