PHP手册整理 - 函数【内置函数(网络)】
作者:互联网
header 函数:
// header — 发送原生 HTTP 头
// URL重定向
header('Location: http://www.example.com/');
// 设置响应状态码
header("HTTP/1.0 404 Not Found");
// 响应一个pdf文件
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');
// 页码不使用缓存
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
ip2long、long2ip 函数:
// ip2long — 将一个IPV4的字符串互联网协议转换成数字格式
$ip = 17.25.68.137;
$long = ip2long($ip);
if ($long == -1 || $long === FALSE) {
echo 'Invalid IP, please try again';
} else {
echo $ip . "\n"; // 192.0.34.166
echo $long . "\n"; // -1073732954
printf("%u\n", ip2long($ip)); // 3221234342
}
// long2ip — 将长整数地址转换为(IPv4) Internet标准点分格式的字符串
function convertIpToString($ip)
{
$long = 4294967295 - ($ip - 1);
return long2ip(-$long);
}
function convertIpToLong($ip)
{
return sprintf("%u", ip2long($ip));
}
setcookie 函数:
// setcookie — 发送Cookie
// setcookie($name[,$value[,$expire[,$path[,$domain[,$secure[,$httponly]]]]]])
// 设置cookie
$value = 'cookie value';
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", true);
// 设置cookie数组
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");
// 读取cookie
echo $_COOKIE["TestCookie"];
// 删除cookie
setcookie("TestCookie", "", time() - 3600);
setcookie("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", true);
socket_create、socket_sendto 函数:
// socket_create — 创建一个套接字(通讯节点)
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
// socket_sendto — 发送消息到套接字,无论它是否连接
$msg = "Ping !";
$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 1223);
socket_close($sock);
标签:内置,函数,ip,long,header,cookie,PHP,setcookie,socket 来源: https://blog.csdn.net/qq_16171697/article/details/113271471