MasterGberry
MasterGberry

Reputation: 2860

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

Upvotes: 0

Views: 165

Answers (2)

MasterGberry
MasterGberry

Reputation: 2860

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. Sorry this question will not help future searches :(

Upvotes: 0

Dan Grossman
Dan Grossman

Reputation: 52372

<?php

session_start();

if (isset($_SESSION['downloading']))
    die("You already have a download in progress.");

$_SESSION['downloading'] = 1;

session_write_close();

//send the file

?>

Upvotes: 1

Related Questions