Php dynamic video

What I am trying to achieve is to create a one-off video link for the user. They watch videos that are about to expire. Let's say the link expires 1 hour after it was originally created.

The problem is how to do it. I can use mod_rewrite to transfer values ​​dynamically in PHP and SQL

So let's say

mysite.ltd/get_video/Jn12lM2NMZ21oMW312/11111111/The-Amazing-Spider-Man.mp4

      

Breakdown: get_video

get_video.php

, Jn12lM2NMZ21oMW312

- a temporary token and 11111111

- timestamp The-Amazing-Spider-Man.mp4

- is the file name.

Based on my conclusion, a marker + timestamp will be generated when visiting the video page and inserted into SQL, if the user has shared the video link, others will not be able to access it as it will not be able to check the validity which is get_video by comparing the IP hashing of the current user and hash token in SQL.

This is my take on how to do this, but I was wondering if anyone has a better solution.

+3


source to share


2 answers


You don't even need to store the token and timestamp. What you want is a hash of the user's IP address, a timestamp, and some nice long secret salt (preferably generated uniquely for each user):

$token = somehash($ip_address . $timestamp . $secret);

$url = 'http://xxx/' . $token . '/' . $timestamp . '/filename';

      



Once the user visits the URL, you play the hash with the user's data. If it's equal and the request hasn't ended yet, don't submit the video yet.

+1


source


You have this part with tokens. The token should only be valid for the current session, or if this link is used to stream video on one page, just create a token for each request. to create secure tokens you can use some secret salt variable which I prefer to keep in your config.php, basically any framework got a salt generated for you.



usually you store the video / file name with id in the database. so create the file path, check the token, you can force the headers to load and readfile () check the first comment, a lot of code in it. this way no one will know the location of your file.

0


source







All Articles