Allow a User to Download a FIle only once Form My site using Php

Hello

Is there anyway of letting a user download a zip file form my website only once or for a certain time period (for example 24 hours)?  I am developing on dreamweaver using php
OR
Are there any off the shelf solutions out there that can perform this function?

Thanks
kevinb4940Asked:
Who is Participating?
 
dianthonymConnect With a Mentor Commented:
Here is an actual script I've used in the past.  (I have removed the html and javascript that this used and given only the php pertinent to this question)  For a good learning experience try and figure out what is being done by this code.  Post back with any questions.  

<? 
 
include('includes/db_connect.php');
 
include('includes/ks_header.php');
 
session_start();
 
if ($_REQUEST['action']=='submit_results') {
 
 
 
		if(isset($_COOKIE['KamaCelebPoll'])) {
 
			$message = "<h3 style='color: #B9216E;margin:2px;'>Sorry you can only vote once, but here are the results.</h3>";
 
			$shop_image = "start_shopping_now.jpg";
 
		} else {
 
		
 
			$sql = "SELECT * FROM vote_user_answers WHERE user_id=".$_SESSION['customer_id'];
 
			$res_vote_check = mysql_query($sql);
 
			if (@mysql_num_rows($res_vote_check)>0) {
 
				$message = "<h3 style='color: #B9216E;margin:2px;'>Sorry you can only vote once, but here are the results.</h3>";
 
				$shop_image = "start_shopping_now.jpg";
 
			} else {
 
				$success="yes";
 
				for ($x=0;$x!=999;$x++) {
 
					$unique_key = generate_random(4);
 
					$sql = "SELECT * FROM vote_user_answers WHERE vote_token='$unique_key'";
 
					$res_token_check = mysql_query($sql);
 
					$token_check = mysql_fetch_array($res_token_check);
 
					if ($token_check['vote_user_answer_id']=="") {
 
						$x = 999;
 
						break;
 
					}
 
				}
 
				
 
				$current_user_id = ($_SESSION['customer_id']=="") ? "-1" : $_SESSION['customer_id'];
 
				
 
				if ($current_user_id==-1) {
 
					$coupon_code = "ks14hc".$unique_key;
 
				} else {
 
					$coupon_code = "ks7hcv1p";
 
				}
 
				
 
				//cat1
 
				$sql = "INSERT INTO vote_user_answers
 
						SET poll_id=1,
 
							vote_cat_id=1,
 
							answer_id=".$_REQUEST['answer1'].",
 
							user_id='$current_user_id',
 
							coupon_code='$coupon_code',
 
							vote_token='".$unique_key."'";
 
				mysql_query($sql);
 
				
 
				
 
				//cat2
 
				$sql = "INSERT INTO vote_user_answers
 
						SET poll_id=1,
 
							vote_cat_id=2,
 
							answer_id=".$_REQUEST['answer2'].",
 
							user_id='$current_user_id',
 
							coupon_code='$coupon_code',
 
							vote_token='".$unique_key."'";
 
				mysql_query($sql);
 
				
 
				
 
				
 
				//cat3
 
				$sql = "INSERT INTO vote_user_answers
 
						SET poll_id=1,
 
							vote_cat_id=3,
 
							answer_id=".$_REQUEST['answer3'].",
 
							user_id='$current_user_id',
 
							coupon_code='$coupon_code',
 
							vote_token='".$unique_key."'";
 
				mysql_query($sql);
 
				
 
				
 
				
 
				//cat4
 
				$sql = "INSERT INTO vote_user_answers
 
						SET poll_id=1,
 
							vote_cat_id=4,
 
							answer_id=".$_REQUEST['answer4'].",
 
							user_id='$current_user_id',
 
							coupon_code='$coupon_code',
 
							vote_token='".$unique_key."'";
 
				mysql_query($sql);
 
				
 
				
 
				
 
				//cat5
 
				$sql = "INSERT INTO vote_user_answers
 
						SET poll_id=1,
 
							vote_cat_id=5,
 
							answer_id=".$_REQUEST['answer5'].",
 
							user_id='$current_user_id',
 
							coupon_code='$coupon_code',
 
							vote_token='".$unique_key."'";
 
				mysql_query($sql);
 
				
 
				
 
				
 
				//cat6
 
				$sql = "INSERT INTO vote_user_answers
 
						SET poll_id=1,
 
							vote_cat_id=6,
 
							answer_id=".$_REQUEST['answer6'].",
 
							user_id='$current_user_id',
 
							coupon_code='$coupon_code',
 
							vote_token='".$unique_key."'";
 
				mysql_query($sql);
 
				
 
				$Month = 2592000 + time(); //this adds 30 days to the current time
 
				setcookie(KamaCelebPoll, date("F jS - g:i a"), $Month);
 
				$_SESSION['celeb_coupon_code'] = $coupon_code;
 
				$shop_image = "ks_banner2.jpg";
 
				
 
				
 
			}
 
		}
 
} else {
 
	if (isset($_COOKIE['KamaCelebPoll'])) {
 
		$shop_image = "start_shopping_now.jpg";
 
	} elseif ($_SESSION['customer_id']!="" && $_SESSION['customer_id']!=0) {
 
		$sql = "SELECT * FROM vote_user_answers WHERE user_id=".$_SESSION['customer_id'];
 
		$res_vote_check = mysql_query($sql);
 
		if (@mysql_num_rows($res_vote_check)>0) {
 
			$shop_image = "start_shopping_now.jpg";
 
		}
 
	} else {
 
		$shop_image = "ks_banner2.jpg";
 
	}
 
}
 
?>

Open in new window

0
 
dianthonymCommented:
In the past I have planted a cookie that my script checks for every time someone wants to access a download.  The script basically says that if there is a cookie do not allow if not it is all right to allow a download.  This of course is not fool proof.  A user simply needs to clear there cookies in order to re download the file.  Hope this helps  
0
 
kevinb4940Author Commented:
Thanks

I have only recently started learning PHP so I am not very good at coding as yet. I  am actually cheating at the minute and using Dreanweavers application panel to create dynamic content for websites.

Could you please advise me on the code I would requie please?
0
 
kevinb4940Author Commented:
Thanks a lot

0
All Courses

From novice to tech pro — start learning today.