]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-go.php
Respect HTTP protocol on redirection
[Github/YOURLS.git] / yourls-go.php
1 <?php\r
2 // Require Files\r
3 require_once( dirname(__FILE__).'/includes/config.php' );\r
4 \r
5 // Connect To Database\r
6 $db = yourls_db_connect();\r
7 \r
8 // Variables\r
9 $keyword = yourls_sanitize_string($_GET['id']);\r
10 \r
11 // First possible exit:\r
12 if ( !$keyword ) {\r
13         header ('Location: '. YOURLS_SITE);\r
14         exit();\r
15 }\r
16 \r
17 $id = yourls_sanitize_int( yourls_string2int($keyword) );\r
18 \r
19 // Get URL From Database\r
20 $table = YOURLS_DB_TABLE_URL;\r
21 $url = stripslashes($db->get_var("SELECT `url` FROM `$table` WHERE id = $id"));\r
22 \r
23 $protocol = $_SERVER["SERVER_PROTOCOL"];\r
24 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )\r
25         $protocol = 'HTTP/1.0';\r
26 \r
27 // URL found\r
28 if(!empty($url)) {\r
29         $update_clicks = $db->query("UPDATE `$table` SET `clicks` = clicks + 1 WHERE `id` = $id");\r
30         header ($protocol.' 301 Moved Permanently');\r
31         header ('Location: '. $url);\r
32 \r
33 // URL not found. Either reserved, or page, or doesn't exist\r
34 } else {\r
35 \r
36         // Do we have a page?\r
37         if (file_exists(dirname(__FILE__)."/pages/$keyword.php")) {\r
38                 yourls_page($keyword);\r
39 \r
40         // Either reserved id, or no such id\r
41         } else {\r
42                 header ($protocol.' 307 Temporary Redirect'); // no 404 to tell browser this might change, and also to not pollute logs\r
43                 header ('Location: '. YOURLS_SITE);\r
44         }\r
45 }\r
46 exit();\r
47 ?>