Thứ Ba, 26 tháng 11, 2019

PHP - Get Country Code by live IP

Detail: function in region area or coutry
Solution: PHP get live IP from browser, get from http://www.geoplugin.net/json.gp?ip=1.2.3.4

<?php
// PHP code to obtain country, city,
// continent, etc using IP Address
 
//$ip = '52.25.109.230';
$ip= $_SERVER [ "REMOTE_ADDR" ];
 
// Use JSON encoded string and converts
// it into a PHP variable
$ipdat = @json_decode(file_get_contents(
    "http://www.geoplugin.net/json.gp?ip=" . $ip));
//print_r($ipdat);
echo 'Your IP: ' . $ip . "<br/>";
echo 'Country Name: ' . $ipdat->geoplugin_countryName . "<br/>";
echo 'Country code: ' . $ipdat->geoplugin_countryCode . "<br/>";
echo 'City Name: ' . $ipdat->geoplugin_city . "<br/>";
echo 'Continent Name: ' . $ipdat->geoplugin_continentName . "<br/>";
echo 'Latitude: ' . $ipdat->geoplugin_latitude . "<br/>";
echo 'Longitude: ' . $ipdat->geoplugin_longitude . "<br/>";
echo 'Currency Symbol: ' . $ipdat->geoplugin_currencySymbol . "<br/>";
echo 'Currency Code: ' . $ipdat->geoplugin_currencyCode . "<br/>";
echo 'Timezone: ' . $ipdat->geoplugin_timezone;
?>

Thứ Hai, 25 tháng 11, 2019

PHP string Serialize Corrector SOLVED

Reason: many string Serialize NOT right format
Solution: check and correction  string. Check many times on internet
Source : from internet. Not remember exactly. So thanks for all

 /*Serialize Corrector*/
 function serialize_corrector($serialized_string){       
        if ( @unserialize($serialized_string) !== true &&  preg_match('/^[aOs]:/', $serialized_string) ) {
             $serialized_string = preg_replace_callback( '/s\:(\d+)\:\"(.*?)\";/s',    function($matches){return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; },   $serialized_string );
        }
        return $serialized_string;
    }