{"id":1119,"date":"2012-07-18T00:10:06","date_gmt":"2012-07-18T00:10:06","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1119"},"modified":"2012-07-18T00:11:04","modified_gmt":"2012-07-18T00:11:04","slug":"how-to-get-ip-address-through-php-code","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2012\/07\/how-to-get-ip-address-through-php-code\/","title":{"rendered":"How to get IP address through php code."},"content":{"rendered":"<p>Every php coder want to store IP address of user for tracking and other different purpose. <\/p>\n<p>Here is the function which i am using in my code to store ip address in db. <\/p>\n<pre lang=\"php\">\r\n    function userIPAdd()\r\n    {\r\n       \/\/This returns the True IP of the client calling the requested page\r\n       \/\/ Checks to see if HTTP_X_FORWARDED_FOR\r\n       \/\/ has a value then the client is operating via a proxy\r\n       $userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];\r\n       if($userIP == \"\")\r\n      { \r\n         $userIP = $_SERVER['REMOTE_ADDR'];  \r\n      }\r\n      \/\/ return the IP we've figured out:\r\n      return $userIP;\r\n    }\r\n<\/pre>\n<p>You can use this simple php function in different ways.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every php coder want to store IP address of user for tracking and other different purpose. Here is the function which i am using in my code to store ip address in db. function userIPAdd() { \/\/This returns the True IP of the client calling the requested page \/\/ Checks to see if HTTP_X_FORWARDED_FOR \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1119","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1119"}],"version-history":[{"count":2,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1119\/revisions"}],"predecessor-version":[{"id":1121,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1119\/revisions\/1121"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}