我有一个“ API”,可以说是我试图在另一台服务器上为应用程序代理api的地方。
目标网址的格式如下: http://example.com/live/username/password/filename.mp4
如何动态重定向到该地址?
这是我到目前为止拥有的php,用于捕获文件名和用户名/密码
<?php
if (isset($_GET['username']))
{
$username=$_GET['username'];
$password=$_GET['password'];
}
else if (isset($_POST['username']))
{
$username=$_POST['username'];
$password=$_POST['password'];
}
$action = isset($_GET['action']) ? $_GET['action'] : '';
$db = new SQLite3('./.dns.db');
$res = $db->query('SELECT * FROM dns');
$arr = array();
while ($row = $res->fetchArray(SQLITE3_ASSOC))
{
$arr[] = $row['url'];
foreach ($arr as $value)
{
$api_call = $value.'/player_api.php?username='.$username.'&password='.$password;
$api = json_decode(file_get_contents($api_call), TRUE);
$api2 = json_decode(json_encode($api["user_info"]) ,TRUE) ;
$auth = $api2["auth"];
if ($auth == 1)
{
$dns = $value;
}
}
}
if (isset($_GET['vod_id']) && $_GET['vod_id'] !== "")
{
$vodid = $_GET["vod_id"];
$vodinfo = file_get_contents($dns.'/player_api.php?username='.$username.'&password='.$password.'&action=get_vod_info&vod_id='.$vodid);
echo $vodinfo;
}
else if (isset($_GET['series_id']) && $_GET['series_id'] !== "")
{
$seriesid = $_GET["series_id"];
$seriesinfo = file_get_contents($dns.'/player_api.php?username='.$username.'&password='.$password.'&action=get_series_info&series_id='.$seriesid);
echo $seriesinfo;
}
else if ($action !== "")
{
$get_actions = file_get_contents($dns.'/player_api.php?username='.$username.'&password='.$password.'&action='.$action);
echo $get_actions;
}
else
{
$login = file_get_contents($dns.'/panel_api.php?username='.$username.'&password='.$password);
echo $login;
}
?>
应用程序将从提供的JSON中读取并获取“文件名”,然后尝试转到api主机上的/ live /,但这也会导致http://example2.net/live/username/password/filename.mp4 不存在。
我想到了htaccess中的某些内容?
我正在尝试为应用提供http://example.com/live/username/password/filename.mp4 不是 http://example2.net/live/username/password/filename.mp4
(example2.net是PHP中的$ dns)
对不起,我知道这是一个错误的解释-希望我已经进行了足够的解释以找到答案。 (第一条帖子)
编辑:我一直在阅读有关查询字符串链接中的文件夹查找的信息,我可以指向此
<?php
if (isset($_GET['username']))
{
$username=$_GET['username'];
$password=$_GET['password'];
$streamid=$_GET['streamid'];
}
else if (isset($_POST['username']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$streamid=$_POST['streamid'];
}
header('Location: http://example.com/live/'.$username.'/'.$password.'/'.$streamid);
?>
我现在只需要弄清楚如何使用htaccess将请求的文件夹网址变成来自的查询字符串
example2.net/live/username/password/file.mp4到 example2.net/live.php?username=username&password=password&streamid=streamid.mp4
答案 0 :(得分:2)
我最终使用了适用于.htaccess的工具
tempfile.NamedTemporaryFile(delete=False)