{"id":788,"date":"2011-02-04T22:56:11","date_gmt":"2011-02-04T17:26:11","guid":{"rendered":"http:\/\/jesin.tk\/?p=788"},"modified":"2013-06-28T15:00:45","modified_gmt":"2013-06-28T09:30:45","slug":"php-ip-address","status":"publish","type":"post","link":"https:\/\/websistent.com\/php-ip-address\/","title":{"rendered":"How to display IP Address in PHP"},"content":{"rendered":"<p>PHP can be used to get the IP Address of a website visitor, IP address of the server hosting the website and resolve the IP address to get the hostname a.k.a reverse DNS records. PHP has predefined $_SERVER array variable using which IP addresses of both visitors and host can be retrieved. The gethostbyaddr() function is used to find out the hostname. The indices REMOTE_ADDR and HTTP_HOST contain the visitor IP address and host IP address<!--more-->To find out the IP address of a visitor using PHP use the $_SERVER[&#8216;REMOTE_ADDR&#8217;] variable. For example, the following code<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php\r\nprint &quot;Your IP address is &quot;.$_SERVER&#x5B;'REMOTE_ADDR'];\r\n?&gt;<\/pre>\n<p>will display the visitor IP address to the visitor himself. If you want to record this IP address insert the value into the database.<\/p>\n<p>To know your web server&#8217;s IP address using PHP use the $_SERVER[&#8216;HTTP_HOST&#8217;] variable.<\/p>\n<p>To get the hostname of the variable use the gethostbyaddr() function with IP address as the parameter. For example<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php\r\nprint gethostbyaddr(&quot;127.0.0.1&quot;);\r\n?&gt;<\/pre>\n<p>will print localhost. If a hostname cannot be resolved the same IP address is returned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP can be used to get the IP Address of a website visitor, IP address of the server hosting the website and resolve the IP address to get the hostname a.k.a reverse DNS records. PHP has predefined $_SERVER array variable using which IP addresses of both visitors and host can be retrieved. The gethostbyaddr() function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2058,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[39],"tags":[24],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to display IP Address in PHP - Jesin&#039;s Blog<\/title>\n<meta name=\"description\" content=\"Leanr how to display or track the IP address of a visitor by using this PHP code\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/websistent.com\/php-ip-address\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to display IP Address in PHP - Jesin&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Leanr how to display or track the IP address of a visitor by using this PHP code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/websistent.com\/php-ip-address\/\" \/>\n<meta property=\"og:site_name\" content=\"Jesin&#039;s Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/JesinsBlog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/a.jesin\" \/>\n<meta property=\"article:published_time\" content=\"2011-02-04T17:26:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-06-28T09:30:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/08\/php.png\" \/>\n\t<meta property=\"og:image:width\" content=\"397\" \/>\n\t<meta property=\"og:image:height\" content=\"255\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jesin A\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jesin_a\" \/>\n<meta name=\"twitter:site\" content=\"@jesin_a\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jesin A\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/websistent.com\/php-ip-address\/\",\"url\":\"https:\/\/websistent.com\/php-ip-address\/\",\"name\":\"How to display IP Address in PHP - Jesin&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/websistent.com\/#website\"},\"datePublished\":\"2011-02-04T17:26:11+00:00\",\"dateModified\":\"2013-06-28T09:30:45+00:00\",\"author\":{\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0\"},\"description\":\"Leanr how to display or track the IP address of a visitor by using this PHP code\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/websistent.com\/php-ip-address\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/websistent.com\/#website\",\"url\":\"https:\/\/websistent.com\/\",\"name\":\"Jesin&#039;s Blog\",\"description\":\"Welcome to the Portal of Technology\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/websistent.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0\",\"name\":\"Jesin A\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g\",\"caption\":\"Jesin A\"},\"sameAs\":[\"https:\/\/websistent.com\/\",\"https:\/\/www.facebook.com\/a.jesin\",\"https:\/\/twitter.com\/jesin_a\"],\"url\":\"https:\/\/websistent.com\/author\/a-jesin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to display IP Address in PHP - Jesin&#039;s Blog","description":"Leanr how to display or track the IP address of a visitor by using this PHP code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/websistent.com\/php-ip-address\/","og_locale":"en_US","og_type":"article","og_title":"How to display IP Address in PHP - Jesin&#039;s Blog","og_description":"Leanr how to display or track the IP address of a visitor by using this PHP code","og_url":"https:\/\/websistent.com\/php-ip-address\/","og_site_name":"Jesin&#039;s Blog","article_publisher":"https:\/\/www.facebook.com\/JesinsBlog","article_author":"https:\/\/www.facebook.com\/a.jesin","article_published_time":"2011-02-04T17:26:11+00:00","article_modified_time":"2013-06-28T09:30:45+00:00","og_image":[{"width":397,"height":255,"url":"https:\/\/websistent.com\/wp-content\/uploads\/2013\/08\/php.png","type":"image\/png"}],"author":"Jesin A","twitter_card":"summary_large_image","twitter_creator":"@jesin_a","twitter_site":"@jesin_a","twitter_misc":{"Written by":"Jesin A","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/websistent.com\/php-ip-address\/","url":"https:\/\/websistent.com\/php-ip-address\/","name":"How to display IP Address in PHP - Jesin&#039;s Blog","isPartOf":{"@id":"https:\/\/websistent.com\/#website"},"datePublished":"2011-02-04T17:26:11+00:00","dateModified":"2013-06-28T09:30:45+00:00","author":{"@id":"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0"},"description":"Leanr how to display or track the IP address of a visitor by using this PHP code","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/websistent.com\/php-ip-address\/"]}]},{"@type":"WebSite","@id":"https:\/\/websistent.com\/#website","url":"https:\/\/websistent.com\/","name":"Jesin&#039;s Blog","description":"Welcome to the Portal of Technology","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/websistent.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0","name":"Jesin A","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/websistent.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g","caption":"Jesin A"},"sameAs":["https:\/\/websistent.com\/","https:\/\/www.facebook.com\/a.jesin","https:\/\/twitter.com\/jesin_a"],"url":"https:\/\/websistent.com\/author\/a-jesin\/"}]}},"_links":{"self":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts\/788"}],"collection":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/comments?post=788"}],"version-history":[{"count":0,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts\/788\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/media\/2058"}],"wp:attachment":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/media?parent=788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/categories?post=788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/tags?post=788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}