网络 函数 业 ,精于勤 荒于嬉.
- 网络 函数 checkdnsrr 给指定的主机(域名)或者IP地址做DNS通信检查
-
发表日期:2021-07-01 08:56:40 | 来源: | 分类:网络 函数
-
checkdnsrr
(PHP 4, PHP 5, PHP 7, PHP 8)
checkdnsrr — 给指定的主机(域名)或者IP地址做DNS通信检查
说明
checkdnsrr(string$host
, string$type
= "MX"): bool根据不同记录(
type
)类型查询主机(host
)相应的DNS记录。参数
-
host
-
主机(
host
)可以是一个IP地址也可以是域名。 -
type
-
解析记录类型(
type
)可能是下面这些类型中的任何一个:A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY。
返回值
如果记录能找到,就返回
true
;如果查找不到该DNS记录或者发生了错误,就返回false
。更新日志
版本 说明 5.3.0 这个函数在Windows平台上也可以使用了。 5.2.4 增加了TXT的记录 类型
。5.0.0 增加了AAAA的记录 类型
。参见
- dns_get_record() - 获取指定主机的DNS记录
- getmxrr() - 获取互联网主机名对应的 MX 记录
- gethostbyaddr() - 获取指定的IP地址对应的主机名
- gethostbyname() - 返回主机名对应的 IPv4地址。
- gethostbynamel() - 获取互联网主机名对应的 IPv4 地址列表
- the named(8) manual page
-
- 网络 函数 closelog 关闭系统日志链接
-
发表日期:2021-07-01 08:56:40 | 来源: | 分类:网络 函数
- 网络 函数 dns_check_record 别名 checkdnsrr()
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
说明
此函数是该函数的别名: checkdnsrr()。
- 网络 函数 dns_get_mx 别名 getmxrr()
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
- 网络 函数 dns_get_record 获取指定主机的DNS记录
-
发表日期:2021-07-01 08:56:40 | 来源: | 分类:网络 函数
-
示例1
1
<?php
2
$result
= dns_get_record(
"php.net"
);
3
print_r(
$result
);
4
?>
示例2
01
<?php
02
/* Request "ANY" record for php.net, and create $authns and $addtl arrays containing list of name servers and any additional records which go with them */
03
$result
= dns_get_record(
"php.net"
, DNS_ANY,
$authns
,
$addtl
);
04
echo
"Result = "
;
05
print_r(
$result
);
06
echo
"Auth NS = "
;
07
print_r(
$authns
);
08
echo
"Additional = "
;
09
print_r(
$addtl
);
10
?>
- 网络 函数 fsockopen 打开一个网络连接或者一个Unix套接字连接
-
发表日期:2021-07-01 08:56:40 | 来源: | 分类:网络 函数
-
示例1
01
<?php
02
$fp
=
fsockopen
(
"www.example.com"
, 80,
$errno
,
$errstr
, 30);
03
if
(!
$fp
) {
04
echo
"$errstr ($errno)<br />\n"
;
05
}
06
else
{
07
$out
=
"GET / HTTP/1.1\r\n"
;
08
$out
.=
"Host: www.example.com\r\n"
;
09
$out
.=
"Connection: Close\r\n\r\n"
;
10
fwrite(
$fp
,
$out
);
11
while
(!
feof
(
$fp
)) {
12
echo
fgets
(
$fp
, 128);
13
}
14
fclose(
$fp
);
15
}
16
?>
示例2
01
<?php
02
$fp
=
fsockopen
(
"udp://127.0.0.1"
, 13,
$errno
,
$errstr
);
03
if
(!
$fp
) {
04
echo
"ERROR: $errno - $errstr<br />\n"
;
05
}
06
else
{
07
fwrite(
$fp
,
"\n"
);
08
echo
fread
(
$fp
, 26);
09
fclose(
$fp
);
10
}
11
?>
- 网络 函数 gethostbyaddr 获取指定的IP地址对应的主机名
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
1
<?php
2
$hostname
=
gethostbyaddr
(
$_SERVER
[
'REMOTE_ADDR'
]);
3
echo
$hostname
;
4
?>
- 网络 函数 gethostbyname 返回主机名对应的 IPv4地址。
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
1
<?php
2
$ip
=
gethostbyname
(
'www.example.com'
);
3
echo
$ip
;
4
?>
- 网络 函数 gethostbynamel 获取互联网主机名对应的 IPv4 地址列表
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
1
<?php
2
$hosts
=
gethostbynamel
(
'www.example.com'
);
3
print_r(
$hosts
);
4
?>
- 网络 函数 gethostname 获取主机名
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
1
<?php
2
echo
gethostname();
3
// may output e.g,: sandie// Or, an option that also works before PHP 5.3echo php_uname('n');
4
// may output e.g,: sandie?>
- 网络 函数 getmxrr 获取互联网主机名对应的 MX 记录
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
getmxrr
(PHP 4, PHP 5, PHP 7, PHP 8)
getmxrr — 获取互联网主机名对应的 MX 记录
说明
getmxrr(string$hostname
, array&$mxhosts
, array&$weight
= ?): bool搜索
hostname
对应的 MX DNS 记录。参数
-
hostname
-
互联网主机名。
-
mxhosts
-
找到的 MX 记录列表存放于
mxhosts
数组。 -
weight
-
提供了
weight
数组后,它会用找到的权重信息填充数组。
返回值
找到记录返回
true
,没找到或者出错时返回false
。更新日志
版本 说明 5.3.0 Windows 平台上也能用这个函数了。 注释
注意:
本函数不应使用于地址验证。 仅在 MX 记录在 DNS 中找到时才会返回,然而根据 » RFC 2821, 没有 MX 记录时,
hostname
本身就是 MX 主机,优先级为0
。注意:
参见
- checkdnsrr() - 给指定的主机(域名)或者IP地址做DNS通信检查
- dns_get_record() - 获取指定主机的DNS记录
- gethostbyname() - 返回主机名对应的 IPv4地址。
- gethostbynamel() - 获取互联网主机名对应的 IPv4 地址列表
- gethostbyaddr() - 获取指定的IP地址对应的主机名
- Linux 手册页面
named(8)
-
- 网络 函数 getprotobyname Get protocol number associated with protocol name
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
01
<?php
02
$protocol
=
'tcp'
;
03
$get_prot
=
getprotobyname
(
$protocol
);
04
if
(
$get_prot
=== FALSE) {
05
echo
'Invalid Protocol'
;
06
}
07
else
{
08
echo
'Protocol #'
.
$get_prot
;
09
}
10
?>
- 网络 函数 getprotobynumber Get protocol name associated with protocol number
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
getprotobynumber
(PHP 4, PHP 5, PHP 7, PHP 8)
getprotobynumber — Get protocol name associated with protocol number
说明
getprotobynumber(int$protocol
): string|falsegetprotobynumber() returns the protocol name associated with protocol
protocol
as per /etc/protocols.参数
-
protocol
-
The protocol number.
返回值
Returns the protocol name as a string, 或者在失败时返回
false
. -
- 网络 函数 getservbyname 获取互联网服务协议对应的端口
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
1
<?php
2
$services
=
array
(
'http'
,
'ftp'
,
'ssh'
,
'telnet'
,
'imap'
,
'smtp'
,
'nicname'
,
'gopher'
,
'finger'
,
'pop3'
,
'www'
);
3
foreach
(
$services
as
$service
) {
4
$port
=
getservbyname
(
$service
,
'tcp'
);
5
echo
$service
.
": "
.
$port
.
"<br />\n"
;
6
}
7
?>
- 网络 函数 getservbyport Get Internet service which corresponds to port and protocol
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
getservbyport
(PHP 4, PHP 5, PHP 7, PHP 8)
getservbyport — Get Internet service which corresponds to port and protocol
说明
getservbyport(int$port
, string$protocol
): string|falsegetservbyport() returns the Internet service associated with
port
for the specifiedprotocol
as per /etc/services.参数
-
port
-
The port number.
-
protocol
-
protocol
is either"tcp"
or"udp"
(in lowercase).
返回值
Returns the Internet service name as a string, 或者在失败时返回
false
. -
- 网络 函数 header_register_callback 调用一个 header 函数
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
01
<?php
02
header(
'Content-Type: text/plain'
);
03
header(
'X-Test: foo'
);
04
function
foo() {
05
foreach
(headers_list()
as
$header
) {
06
if
(
strpos
(
$header
,
'X-Powered-By:'
) !== false) {
07
header_remove(
'X-Powered-By'
);
08
}
09
header_remove(
'X-Test'
);
10
}
11
}
12
$result
= header_register_callback(
'foo'
);
13
echo
"a"
;
14
?>
- 网络 函数 header_remove 删除之前设置的 HTTP 头
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
1
<?php
2
header(
"X-Foo: Bar"
);
3
header(
"X-Bar: Baz"
);
4
header_remove(
"X-Foo"
);
5
?>
示例2
1
<?php
2
header(
"X-Foo: Bar"
);
3
header(
"X-Bar: Baz"
);
4
header_remove();
5
?>
- 网络 函数 header 发送原生 HTTP 头
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
1
<html><?php
2
/* This will give an error. Note the output * above, which is before the header() call */
3
header(
'Location: http://www.example.com/'
);
4
exit
;
5
?>
示例2
1
<?php
2
// 本示例演示了 "HTTP/" 的特殊例子,典型用法的最佳实践,包括:// 1. header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
3
// (覆盖 http 状态消息,兼容还在使用 HTTP/1.0 的客户端)// 2. http_response_code(404);
4
(使用默认消息)header(
"HTTP/1.1 404 Not Found"
);
5
?>
示例3
1
<?php
2
header(
"Location: http://www.example.com/"
);
3
/* Redirect browser */
4
/* Make sure that code below does not get executed when we redirect. */
5
exit
;
6
?>
示例4
1
<?php
2
header(
'WWW-Authenticate: Negotiate'
);
3
header(
'WWW-Authenticate: NTLM'
, false);
4
?>
示例5
1
<?php
2
// 输出 PDF 文件header('Content-type: application/pdf');
3
// 名称为 downloaded.pdfheader('Content-Disposition: attachment;
4
filename=
"downloaded.pdf"
');
5
// 该 PDF 来源于 original.pdfreadfile('original.pdf');
6
?>
示例6
1
<?php
2
header(
"Cache-Control: no-cache, must-revalidate"
);
3
// HTTP/1.1header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
4
// 过去的日期?>
示例7
1
<?php
2
/* 根据当前请求所在的目录,重定向到不同的页面 */
3
$host
=
$_SERVER
[
'HTTP_HOST'
];
4
$uri
= rtrim(dirname(
$_SERVER
[
'PHP_SELF'
]),
'/\\'
);
5
$extra
=
'mypage.php'
;
6
header(
"Location: http://$host$uri/$extra"
);
7
exit
;
8
?>
- 网络 函数 headers_list 返回已发送的 HTTP 响应头(或准备发送的)
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
01
<?php
02
/* setcookie() 会自己添加一个响应头 */
03
setcookie(
'foo'
,
'bar'
);
04
/* 添加自定义的响应头 大多数客户端会主动忽略 */
05
header(
"X-Sample-Test: foo"
);
06
/* 响应中指定内容为明文 text */
07
header(
'Content-type: text/plain'
);
08
/* 所以会发送什么头呢? */
09
var_dump(headers_list());
10
?>
- 网络 函数 headers_sent 检测 HTTP 头是否已经发送
-
发表日期:2021-07-01 08:56:41 | 来源: | 分类:网络 函数
-
示例1
01
<?php
02
// 没有 HTTP 头就发送一个if (!headers_sent()) {
03
header(
'Location: http://www.example.com/'
);
04
exit
;
05
}
06
// 使用 file 和 line 参数选项的例子// 注意 $filename 和 $linenum 用于下文中使用// 所以不要提前为它们赋值if (!headers_sent($filename, $linenum)) {
07
header(
'Location: http://www.example.com/'
);
08
exit
;
09
// 很有可能在这里触发错误}
10
else
{
11
echo
"Headers already sent in $filename on line $linenum\n"
.
"Cannot redirect, for now please click this <a "
.
"href=\"http://www.example.com\">link</a> instead\n"
;
12
exit
;
13
}
14
?>
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)