forked from YOURLS/YOURLS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyourls-go.php
39 lines (31 loc) · 966 Bytes
/
yourls-go.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// Require Files
require_once( dirname(__FILE__).'/includes/config.php' );
// Variables
$id = ( isset( $_GET['id'] ) ? $_GET['id'] : '' );
$keyword = yourls_sanitize_string( $id );
// First possible exit:
if ( !$keyword ) {
yourls_redirect( $url, 301 );
}
// Get URL From Database
$url = yourls_get_longurl( $keyword );
// URL found
if( !empty($url) ) {
// Update click count in main table
$update_clicks = yourls_update_clicks( $keyword );
// Update detailed log for stats
$log_redirect = yourls_log_redirect( $keyword );
yourls_redirect( $url, 301 );
// URL not found. Either reserved, or page, or doesn't exist
} else {
// Do we have a page?
if (file_exists(dirname(__FILE__)."/pages/$keyword.php")) {
yourls_page($keyword);
// Either reserved id, or no such id
} else {
yourls_redirect( YOURLS_SITE, 307 ); // no 404 to tell browser this might change, and also to not pollute logs
}
}
exit();
?>