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