This topic is locked

Limiting file downloads

8/20/2007 6:07:36 AM
PHPRunner General questions
S
Samadhi author

I want to put afile on teh user page. The user will be limited as to teh number of times they can download this file; the admin user will be able to set the number of times the user can download the file when they add a new user.
How can i do this?

J
Jane 8/20/2007

Hi,
you can do it using Edit page: Before display event on the Events tab.

Here is a sample:

global $conn,$strTableName;

$str = "select СounterField from ".$strTableName." where FieldID=".$_REQUEST["editid1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

if ($data["СounterField"]>5)

{

//redirect to the list page

header("Location: TableName_list.php?a=return");

exit();

}

else

{

//СounterField = СounterField + 1

$strUpdate = "update ".$strTableName." set СounterField=СounterField+1 where FieldID=".$_REQUEST["editid1"];

db_exec($strUpdate,$conn);

}



where СounterField and FieldID are your actual field names.