]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-go.php
Better action names and correct variable
[Github/YOURLS.git] / yourls-go.php
1 <?php\r
2 define('YOURLS_GO', true);\r
3 require_once( dirname(__FILE__).'/includes/load-yourls.php' );\r
4 \r
5 // Variables should be defined in yourls-loader.php, if not try GET request (old behavior of yourls-go.php)\r
6 if( !isset( $keyword ) && isset( $_GET['id'] ) )\r
7         $keyword = $_GET['id'];\r
8 $keyword = yourls_sanitize_string( $keyword );\r
9 \r
10 // First possible exit:\r
11 if ( !$keyword ) {\r
12         yourls_do_action( 'redirect_no_keyword' );\r
13         yourls_redirect( YOURLS_SITE, 301 );\r
14 }\r
15 \r
16 // Get URL From Database\r
17 $url = yourls_get_keyword_longurl( $keyword );\r
18 \r
19 // URL found\r
20 if( !empty($url) ) {\r
21         // Update click count in main table\r
22         $update_clicks = yourls_update_clicks( $keyword );\r
23         // Update detailed log for stats\r
24         $log_redirect = yourls_log_redirect( $keyword );\r
25         \r
26         yourls_do_action( 'redirect_shorturl', $url );\r
27 \r
28         yourls_redirect( $url, 301 );\r
29 \r
30 // URL not found. Either reserved, or page, or doesn't exist\r
31 } else {\r
32 \r
33         // Do we have a page?\r
34         if ( file_exists(YOURLS_PAGEDIR."/$keyword.php") ) {\r
35                 // Include YOURLS functions we've skipped, they might be of use\r
36                 require_once( YOURLS_INC.'/functions-html.php' );\r
37                 yourls_page($keyword);\r
38 \r
39         // Either reserved id, or no such id\r
40         } else {\r
41                 yourls_do_action( 'redirect_keyword_not_found', $keyword );\r
42                 \r
43                 yourls_redirect( YOURLS_SITE, 307 ); // no 404 to tell browser this might change, and also to not pollute logs\r
44         }\r
45 }\r
46 exit();\r