nginx rtmp 推流权限验证问题。
操作系统:windows 2003 server
web服务器+直播系统:nginx 1.12.1 nginx-rtmp-module 1.2.0
推流设备:手机客户端,网页推流,obs
推流地址:rtmp://192.168.1.1:8090/live/test?pass=123
test为用户名,123为密码
现在的情况是live/后面不管写什么都可以推出去,虽然也触发了publish.php页面,现在是不管有没有用户都推,也查询了数据库,查询到了用户名该怎么处理,没有查询到该怎么处理,不知道写什么,下边程序有说明
nginx.conf配置(部分):
listen 1935;
notify_method POST;
application live {
live on;
publish_notify on;
#当有设备推流时,触发publish.php
on_publish 192.168.1.1:8090/publish.php;
}
publish.php文件代码:
<?php
@$name=trim($_REQUEST["name"]);
@$pass=trim($_REQUEST["pass"]);
//加了一个写文件操作,是为了验证是否触发了publish.php这个文件,经验证确实触发了。
$myfile = fopen("testfile.txt", "w");
//如果都不是空值执行数据库查询
if(!empty($name) and !empty($pass))
{
require "function_php/function.php";
conn();//调取连接数据库函数
//查询数据库中是否存在此用户
$sql="select * from tbl_user where user_name='$name' and user_pass='$pass'";
$query=$conn->query($sql);
$row=$query->num_rows;
if ($row ==1 )
{
//如果有用户存在把用户名、密码写到文件里,也确实写了。现在的问题是验证正确以后,不知道怎么写,如何告诉nginx.conf文件
fwrite($myfile,$name."\n");
fwrite($myfile,$pass."\n");
fwrite($myfile,$row."\n");
}
else
{
//如果用户不存在也把用户名和密码写到文件里 验证不正确该怎么写呢?如何停止推流
fwrite($myfile,$name."\n");
fwrite($myfile,$pass."\n");
fwrite($myfile,$row."\n");
}
$query->free_result();
$conn->close();
}
else
{
header('HTTP/1.0 404 Not Found');
}
fclose($myfile);
?>