I am working on a project which need to send a video link to any email. But this video link will expire after 3 days automatically and video url should not work. How can I do it? Any help will be appreciated.
You have to store the videos Ids along with their creation dateTime in a database, so you can query them in your application layer (PHP).
the structure of your URL you are going to serve could be something like this
domain/videos.php?video_id=123456
the database table
-- videos table
+----------+---------------------------+
| video_id | creation_datetime |
+----------+---------------------------+
| 123456 | 2017-07-18 14:21:19 |
| 123457 | 2017-07-16 11:21:50 |
+----------+---------------------------+
The php script videos.php
<?php
if(empty($_GET['video_id'])){
die('no video to show');//TODO: proper msg
}
$mysqli = new mysqli("example.com", "user", "password", "database");
$query = "SELECT video_id FROM videos WHERE video_id = ? AND creation_datetime >= ?";
$stmt = $mysqli->prepare($query);
!$stmt ? die('error') : "";
//before 3 days
$stmt->bind_param('ss', $_GET['video_id'], date("Y-m-d H:i:s", time() - 3 * 24 * 60* 60));
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows){
//give the video
}else{
die('sorry, the video is expired');
}
exit;
Now, depending on the time I write this domain/videos.php?video_id=123456
would be served and domain/videos.php?video_id=123457
is expired