{"id":29,"date":"2011-10-25T06:58:43","date_gmt":"2011-10-25T06:58:43","guid":{"rendered":"http:\/\/www.sandykadam.com\/?p=29"},"modified":"2012-01-03T12:10:40","modified_gmt":"2012-01-03T12:10:40","slug":"get-remote-ip-address-in-php","status":"publish","type":"post","link":"https:\/\/www.sandykadam.com\/blog\/programming-stuff\/php\/get-remote-ip-address-in-php\/","title":{"rendered":"Get Remote IP Address in PHP"},"content":{"rendered":"<p>PHP Script to find out the IP address.<\/p>\n<p>[code type=php]<\/p>\n<p>&lt;?php<br \/>\nfunction getRemoteIPAddress() {<br \/>\n$ip = $_SERVER[&#8216;REMOTE_ADDR&#8217;];<br \/>\nreturn $ip;<br \/>\n}<br \/>\n?&gt;<br \/>\n[\/code]<\/p>\n<p>The above code will not work in case your client is behind proxy server. In that case use below function to get real IP address of client.<\/p>\n<p>[code type=php]<br \/>\n&lt;?php<br \/>\nfunction getRealIPAddr()<br \/>\n{<br \/>\nif (!empty($_SERVER[&#8216;HTTP_CLIENT_IP&#8217;])) \/\/check ip from share internet<br \/>\n{<br \/>\n$ip=$_SERVER[&#8216;HTTP_CLIENT_IP&#8217;];<br \/>\n}<br \/>\nelseif (!empty($_SERVER[&#8216;HTTP_X_FORWARDED_FOR&#8217;])) \/\/to check ip is pass from proxy<br \/>\n{<br \/>\n$ip=$_SERVER[&#8216;HTTP_X_FORWARDED_FOR&#8217;];<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n$ip=$_SERVER[&#8216;REMOTE_ADDR&#8217;];<br \/>\n}<br \/>\nreturn $ip;<br \/>\n}<br \/>\n?&gt;<br \/>\n[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP Script to find out the IP address.<br \/>\n[code type=php]<br \/>\n&lt;?php<br \/>\nfunction getRemoteIPAddress() &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[24],"tags":[37],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-php","tag-php-2"],"aioseo_notices":[],"views":1621,"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p25uYH-t","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":15,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts\/29\/revisions\/31"}],"wp:attachment":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}