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