防止课程视频被直接访问|电子学习


Prevent lesson videos from being accessed directly | e-learning

电子学习平台:课程教师将在创建课程的同时上传视频。

             create            has            consists of
instructor ---------> course ------> lesson --------------> video

当学生对课程c1的课程l1进行GET请求时,服务器将响应以下JSON响应(如果学生登录并注册了该课程)

{
    "success" : [
        {
            "courseid" : "c1",
            "lessonid" : "l1",
            "title" : "Sample lesson #1",
            "video" : "http://www.example.com/lesson/l1/video.mp4",
            "videothumbnail" : "http://www.example.com/lesson/l1/videothumbnail.png"
        }
    ]
}

使课程视频只能从 http://www.example.com/course?courseid=c1& lessonid = l1 学生登录并注册课程时的页面。

我做了什么

我通过在中写入以下行来阻止直接访问课程视频。htaccess文件,我把它放在lesson文件夹中。

#prevent direct access to the lesson folder and its contents
order deny,allow
deny from all
allow from XXX.XXX.XXX.XXX

其中XXX.XXX.XXX.XXX为服务器的IP地址。

我甚至尝试了以下方法:

#prevent direct access to the lesson folder and its contents
deny from all

现在,如果在浏览器中复制粘贴视频链接,则显示以下错误信息:

Forbidden
You don't have permission to access /lesson/l1/video.mp4 on this server.

所以,当我在浏览器中复制粘贴视频链接时,它成功地阻止了视频的直接访问http://www.example.com/lesson/l1/video.mp4

但是当我尝试从课程页面http://www.example.com/course?courseid=c1&lessonid=l1访问视频时,我在浏览器控制台中得到以下错误消息。

Failed to load resource: the server responded with a status of 403 (Forbidden)

请建议一种方法,使课程视频只能从课程页面访问。

后端

    MySQL db

你可以把include文件夹移出web-root目录。如果你想阻止对整个includes文件夹的直接访问那么你可以在文件夹中放一个。htaccess文件只包含:

deny from all

像这样,你不能打开文件夹中的任何文件,你可以把它们包含在php中,没有任何问题。