Archive by Author: Tom

Get European Union (EU) countries with standard VAT rate (PHP)

function get_european_union_countries_with_vat_rate() {
	return array( 
		'AT' => 20, 
		'BE' => 21, 
		'BG' => 20, 
		'CY' => 19, 
		'CZ' => 21, 
		'DE' => 19, 
		'DK' => 25, 
		'EE' => 20, 
		'ES' => 21,
		'FI' => 24,
		'FR' => 20,
		'GB' => 20, 
		'GR' => 24, 
		'HU' => 27, 
		'HR' => 25, 
		'IE' => 23, 
		'IT' => 22, 
		'LT' => 21,
		'LU' => 17,
		'LV' => 21,
		'MT' => 18, 
		'NL' => 21, 
		'PL' => 23, 
		'PT' => 23, 
		'RO' => 19, 
		'SE' => 25, 
		'SI' => 22, 
		'SK' => 20,
	);		
}

Get currency exchange rate in PHP

/*
 * Functions gets currency exchange rate from rate-exchange.appspot.com server.
 * returns rate on success, else false
 */
function get_exchange_rate( $currency_from, $currency_to ) {
      $url = 'http://rate-exchange.appspot.com/currency?from=' . $currency_from . '&to=' . $currency_to;
      $exchange_rate = json_decode( file_get_contents( $url ) );
      return ( isset( $exchange_rate->rate ) ) ? $exchange_rate->rate : false;
}

Get user IP in PHP

/*
 * returns IP on success, null on error
 */
function get_the_ip() {
    $ip = null;
    if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}