douao1959 2017-07-20 11:04
浏览 24
已采纳

我怎样才能创建在几天后过期的URL?

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.

  • 写回答

1条回答 默认 最新

  • dsiy62758 2017-07-20 11:33
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置