Example #1
0
/**
 * Log a redirect (for stats)
 *
 * This function does not check for the existence of a valid keyword, in order to save a query. Make sure the keyword
 * exists before calling it.
 *
 * @since 1.4
 * @param string $keyword short URL keyword
 * @return mixed Result of the INSERT query (1 on success)
 */
function yourls_log_redirect($keyword)
{
    // Allow plugins to short-circuit the whole function
    $pre = yourls_apply_filter('shunt_log_redirect', false, $keyword);
    if (false !== $pre) {
        return $pre;
    }
    if (!yourls_do_log_redirect()) {
        return true;
    }
    global $ydb;
    $table = YOURLS_DB_TABLE_LOG;
    $keyword = yourls_escape(yourls_sanitize_string($keyword));
    $referrer = isset($_SERVER['HTTP_REFERER']) ? yourls_escape(yourls_sanitize_url($_SERVER['HTTP_REFERER'])) : 'direct';
    $ua = yourls_escape(yourls_get_user_agent());
    $ip = yourls_escape(yourls_get_IP());
    $location = yourls_escape(yourls_geo_ip_to_countrycode($ip));
    return $ydb->query("INSERT INTO `{$table}` (click_time, shorturl, referrer, user_agent, ip_address, country_code) VALUES (NOW(), '{$keyword}', '{$referrer}', '{$ua}', '{$ip}', '{$location}')");
}
Example #2
0
function yourls_log_redirect($keyword)
{
    if (!yourls_do_log_redirect()) {
        return true;
    }
    global $ydb;
    $table = YOURLS_DB_TABLE_LOG;
    $keyword = yourls_sanitize_string($keyword);
    $referrer = isset($_SERVER['HTTP_REFERER']) ? yourls_sanitize_url($_SERVER['HTTP_REFERER']) : 'direct';
    $ua = yourls_get_user_agent();
    $ip = yourls_get_IP();
    $location = yourls_geo_ip_to_countrycode($ip);
    return $ydb->query("INSERT INTO `{$table}` VALUES ('', NOW(), '{$keyword}', '{$referrer}', '{$ua}', '{$ip}', '{$location}')");
}