简体   繁体   English

如何限制使用会话下载的文件数

[英]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.

相关问题 如何保护PHP文件免遭下载? - How to secure PHP files from being downloaded? 如何保护PDF文件不被下载或复制 - How to protect PDF files from being downloaded or copied 如何给使用FPDF库下载的PDF自定义名称? - How to give a custom name to the PDF being downloaded using FPDF library? 正在下载 PHP 文件而不是在网站上显示 - PHP Files Being Downloaded instead of showing on website 如何使用url限制正在查看或下载的文件? 我希望使用PHP脚本下载相同的文件 - how can i restrict a file being viewed or downloaded using url? i want same file to be downloaded using php script 如何防止PHP文件被下载? 有人可以通过哪些方式下载它们? - How to prevent PHP files from being downloaded? And what are some ways someone can download them? 文件未下载,PHP超时并使用Expect - File not downloaded and being timeout with PHP and using Expect 如何禁止在“ _private / session”目录中创建会话文件? - How can I Disable session files from being created in “_private/session” directory? nginx:重写后正在下载PHP文件 - nginx: PHP-files are being downloaded after rewrite Nginx + Magento配置问题。 正在下载PHP文件 - Nginx + Magento configuration problems. PHP files are being downloaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM