我在建立视频观看网站时遇到一些问题。 该站点的主要目的是仅使用url一次并阻止下载,因此我做了一些逻辑工作,并在另一个php上使用“ echo”获取了数据。 这是我的代码。 viedoview.php
<video controls="" style="width:100%; height:100%;" >
<source src="video.php?vid=<?php echo $token_encrypted; ?>&token=<?php echo $tokenUrl; ?>">
</video>
video.php
session_start();
// Get Token
$token = $_GET['vid'];
// Get Current Session ID
$prev= session_id();
// Test the session variable token is set
$tokenUrl=$_GET['token'];
if(isset($_SESSION['setToken']))
{
// This was a one time token and this is your security
unset($_SESSION['setToken']);
$token=str_replace(' ','+',$token);
// Now we will re-encrypt the token
$token = openssl_decrypt($token,"aes128",session_id(),'0123456789123456');
// Now Regenerate the session id
session_regenerate_id();
// Now re-encrypt the token with a key combination of both new and old ids
$token = openssl_encrypt($token,$prev.session_id(),'0123456789123456');
}
else
{
// If token was not matched,we have changed the id therefore the next script will not be able to decrypt the token
session_regenerate_id(true);
}
header("Location: includes\access.php?id=".$prev."&vid=".$token."&tokenUrl=".$tokenUrl);
?>
access.php
<?php
session_start();
include_once '../DBConnect.php';
// Decrypt the Token to get back the video file name
$tokenUrl=$_GET['tokenUrl'];
$database = new dbConnect();
$db = $database->openConnection();
$sql="select isExpired from tbl_uploaded_videos where oneTimeUrl='$tokenUrl'";
$user = $db->query($sql);
$result = $user->fetchAll(PDO::FETCH_ASSOC);
if($result[0]['isExpired']=='0'||$result[0]['isExpired']=='1') {
$vid=$_GET['vid'];
$vid=str_replace(' ',$vid);
$token = openssl_decrypt($vid,$_GET['id'].session_id(),'0123456789123456');
// Check if file exists
if(file_exists("../videos/".$token))
{
// Another important point here is a session id regeneration
session_regenerate_id(true);
$file = "../videos/".$token;
$file_size = filesize($file);
$file_pointer = fopen($file,"r");
$data = fread($file_pointer,$file_size);
header("Content-type: video/mp4");
// var_dump($data);
echo $data;
$sql="UPDATE tbl_uploaded_videos SET isExpired='0' where oneTimeUrl='$tokenUrl'";
$user = $db->query($sql);
}
else {
echo "Error: File Does not exists";
}
}
else
{
}
?>
它在Google Chrome和Mozilla Firefox中运行良好,但在Safari中不起作用。 我只能看到黑屏。 我该如何解决这个问题?我需要帮助