函数名称:radius_put_string()
适用版本:PHP 4, PHP 5, PHP 7
函数说明:radius_put_string() 函数用于将一个字符串添加到 RADIUS 包中。
语法:bool radius_put_string ( resource $radius_handle , int $type , string $value )
参数:
- radius_handle: RADIUS 连接句柄,通过 radius_auth_open() 或 radius_acct_open() 函数获取。
- type: 字段类型,可以是以下常量之一:
- RADIUS_USER_NAME: 用户名
- RADIUS_USER_PASSWORD: 用户密码
- RADIUS_CHAP_PASSWORD: CHAP 密码
- RADIUS_NAS_IP_ADDRESS: NAS IP 地址
- RADIUS_NAS_PORT: NAS 端口
- 其他可用常量参见官方文档。
- value: 要添加的字符串值。
返回值:成功时返回 TRUE,失败时返回 FALSE。
示例:
$radius_handle = radius_auth_open();
if ($radius_handle) {
$username = "john_doe";
$password = "secret";
$nas_ip = "192.168.0.1";
// 添加用户名字段
if (!radius_put_string($radius_handle, RADIUS_USER_NAME, $username)) {
echo "Failed to put username in RADIUS packet.";
exit;
}
// 添加密码字段
if (!radius_put_string($radius_handle, RADIUS_USER_PASSWORD, $password)) {
echo "Failed to put password in RADIUS packet.";
exit;
}
// 添加NAS IP地址字段
if (!radius_put_string($radius_handle, RADIUS_NAS_IP_ADDRESS, $nas_ip)) {
echo "Failed to put NAS IP address in RADIUS packet.";
exit;
}
// 发送RADIUS请求
$result = radius_send_request($radius_handle);
if ($result == RADIUS_ACCESS_ACCEPT) {
echo "Access granted!";
} else {
echo "Access denied!";
}
// 关闭RADIUS连接
radius_close($radius_handle);
} else {
echo "Failed to open RADIUS connection.";
exit;
}
以上示例演示了如何使用 radius_put_string() 函数将用户名、密码和NAS IP地址添加到 RADIUS 包中,并发送 RADIUS 请求进行认证。注意,示例中的参数值仅供参考,请根据实际需求修改。