0

I am using gethostbyname() for checking IP address for an URL, but it returns invalid IP.

Here is my code :


<?php 
echo gethostbyname('login.sarkarijobs.xyz');
?>

Returns XXX.XXX.XXX.XXX


ping login.sarkarijobs.xyz

Returns ping: unknown host login.sarkarijobs.xyz


dig login.sarkarijobs.xyz

Returns

; <<>> DiG 9.10.3-P4-Ubuntu <<>> login.sarkarijobs.xyz
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 20595
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;login.sarkarijobs.xyz.     IN  A

;; AUTHORITY SECTION:
sarkarijobs.xyz.    9043    IN  SOA ns21.iserverplanet.net. info.iserverplanet.net. 2017102407 3600 7200 1209600 86400

;; Query time: 0 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Fri Nov 03 13:02:23 IST 2017
;; MSG SIZE  rcvd: 113

Trying PHP: gethostbyname bug but not success.

How to do this ?

helpdoc
  • 1,910
  • 14
  • 36
  • 1
    As long as there is no A-record in the zone, there is nothing that `gethostbyname` could resolve. Make sure the domain can be queried against a DNS server. – Michael Hirschler Nov 03 '17 at 07:45
  • 1
    This is not related to any PHP bug. The output of `ping` and `dig` clearly tell that the host name cannot be resolved. Either it doesn't exist or it is not available in the context where you try to resolve it (it may exist in a private network and be completely unknown outside it). The bottom line is: apart from registering the name (or fixing the DNS if the name is registered but improperly configured) there is nothing you can do. And btw, PHP [`gethostbyname()`](http://php.net/manual/en/function.gethostbyname.php) works as described in the documentation (it returns the hostname). – axiac Nov 03 '17 at 07:52

0 Answers0