Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\main::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/cms.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\main::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP根据URL获取IP - 互联网笔记

略微加速

略速 - 互联网笔记

PHP根据URL获取IP

2021-11-02 leiting (2923阅读)

标签 PHP

gethostbyname

(PHP 4, PHP 5, PHP 7)

gethostbyname — 返回主机名对应的 IPv4地址。

说明

gethostbyname ( string $hostname ) : string

返回主机名 hostname 对应的 IPv4 互联网地址。

参数


  • hostname

  • 主机名

返回值

成功时返回 IPv4 地址,失败时原封不动返回 hostname 字符串。

范例


Example #1 简单的 gethostbyname() 例子

<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

参见


  • gethostbyaddr() - 获取指定的IP地址对应的主机名

  • gethostbynamel() - 获取互联网主机名对应的 IPv4 地址列表

  • inet_pton() - Converts a human readable IP address to its packed in_addr representation

  • inet_ntop() - Converts a packed internet address to a human readable representation


北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3