简体   繁体   中英

Get website header with IP

I want to get the header from a website with the IP address.

I used get_header() but this only works with URL! Are there other ways to do this? Without using gethostbyaddre .

You can actually use an IP. Since there's no code, I can't tell where you're going wrong. But I can tell how it should be done:

$url = 'http://173.194.65.101/';
$headers = get_headers($url);
print_r($headers);
  • You have an IP address, eg: 127.0.0.1

  • You want to use get_headers() (with trailing s )

  • ...but get_headers() expects a URL :

     array get_headers ( string $url [, int $format = 0 ] ) 
  • You add http:// and you get a URL: http://127.0.0.1 —voilá!

使用$ _SERVER ['REMOTE_ADDR']获取IP地址。

您可以进行cUrl调用而不是分析并从服务器的响应中提取标头。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM