Get City Country By IP Address in PHP

/*Get user ip address*/ $ip_address=$_SERVER[‘REMOTE_ADDR’]; /*Get user ip address details with*/ $geopluginURL=’’.$ip_address; $addrDetailsArr = unserialize(file_get_contents($geopluginURL)); /*Get City name by return array*/ $city = $addrDetailsArr[‘geoplugin_city’]; /*Get Country name by return array*/ $country = $addrDetailsArr[‘geoplugin_countryName’]; /*Comment out these line to see all the posible details*/ /*echo ‘<pre>’; print_r($addrDetailsArr); die();*/ if(!$city){ $city=’Not Define’; }if(!$country){ $country=’Not Define’; } echo ‘<strong>IP Address</strong>:- ‘.$ip_address.'<br/>’; echo ‘<strong>City</strong>:- ‘.$city.'<br/>’; echo ‘<strong>Country</strong>:- ‘.$country.'<br/>’;[mks_button size="medium" title="View Demo" style="squared" url="" target="_blank" bg_color="#dd3333" txt_color="#FFFFFF" icon="fa-play" icon_type="fa" nofollow="0"] [sdm_download id="7047" fancy="1" show_size="1" show_version="1"]]]>

Anuj Kumar

This is Anuj Kumar. I’m a professional web developer with 4+ year experience. I write blogs in my free time. I love to learn new technologies and share with others.
I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials.

Recommended Tutorials for you


Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.