[英]How to limit # of files being downloaded using session
I have been using a database implementation to limit only one download at a time on my server. 我一直在使用数据库实现来限制一次只能在我的服务器上进行一次下载。 This is kind of error prone and has known issues, so I thought about trying to do it with the session variables instead. 这有点容易出错,并且存在已知问题,因此我考虑过尝试使用会话变量来实现。 Only problem is that I use the following command before i start sending the file so that the user can browse the site still while downloading: 唯一的问题是,在开始发送文件之前,我使用了以下命令,以便用户在下载时仍可以浏览站点:
session_write_close();
I want to check if a variable in the session exists, then if not add one, close session, then re-open the same session and delete the old variable that i added. 我想检查会话中是否存在变量,如果不存在,请关闭会话,然后重新打开同一会话并删除我添加的旧变量。 Is this possible? 这可能吗? Or is there an easier way to go about this? 还是有更简单的方法来解决这个问题? Or should i just stick with db implementation. 还是我应该坚持执行数据库。
Thanks 谢谢
<?php
session_start();
if (isset($_SESSION['downloading']))
die("You already have a download in progress.");
$_SESSION['downloading'] = 1;
session_write_close();
//send the file
?>
In the end I could not find a stable Session solution, as it was causing corruption in the session, so I ended up just sticking with my database implementation for now. 最后,我找不到稳定的Session解决方案,因为它会导致Session损坏,因此最终我只是坚持使用数据库实现。 Sorry this question will not help future searches :( 抱歉,这个问题对以后的搜索没有帮助:(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.