Example :
<?php function get_client_ip() { $ipAddress = ''; if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipAddress = $_SERVER['HTTP_CLIENT_IP']; else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_X_FORWARDED'])) $ipAddress = $_SERVER['HTTP_X_FORWARDED']; else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipAddress = $_SERVER['HTTP_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_FORWARDED'])) $ipAddress = $_SERVER['HTTP_FORWARDED']; else if(isset($_SERVER['REMOTE_ADDR'])) $ipAddress = $_SERVER['REMOTE_ADDR']; else $ipAddress = 'UNKNOWN'; return $ipAddress; } $client_ip = get_client_ip(); echo $client_ip; ?> /* Output : 172.65.24.12 */
Technical Architect
Kuala Lumpur, Malaysia
I'm a Full Stack Web Developer working in a MNC and passionate of developing modern web and mobile applications.
I have designed and developed CodephpOnline & CodephpOnline Wiki platform to expatiate my coding and technology learning experiences.
In my leisure time, I write technical articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Linux, Angular, Ionic, ReactJS, NodeJS, AJAX, jQuery, Cloud and more.