Re: File Downloads

From: Date: Fri, 28 May 2010 23:39:48 +0000
Subject: Re: File Downloads
References: 1 2 3 4 5 6 7 8  Groups: php.db 
Request: Send a blank email to php-db+get-47204@lists.php.net to get a copy of this message
This is for a small project of limited edition audio or pictures or scripts, etc. Hens, "I'd like" to limit each user in the allotted 150 to be able to download (whatever it is) only once. But up to 150 users can get in on it kind of thing. Karl On May 28, 2010, at 6:36 PM, Karl DeSaulniers wrote:
Yes the users will have gone through a registration and login to get to the downloads. The files will be served from MySQL and output to HTML of Flash. Karl On May 28, 2010, at 6:27 PM, Systems wrote:
While DB logging is definitely the way to do it, I would suggest not to rely on ip logging as authentication mechanism for following reasons: Most end-users are on a dynamic IP. One IP can/will serve multiple users (any large institution with wireless (Universities, Hospitals etc.) will have hundreds or thousands of people surfing with one public IP - which is the IP you're logging) Is there any reason not to log them in by personalized means? (such as email/username) -----Original Message----- From: Karl DeSaulniers [mailto:karl@designdrumm.com] Sent: Friday, May 28, 2010 6:39 PM To: php-db@lists.php.net Subject: Re: [PHP-DB] File Downloads On May 28, 2010, at 4:49 PM, Michael Stowe wrote:
For that you would probably need to setup a databased system in which (best scenario) they would need to register prior to downloading or (not so secure) capture their IP address and prevent that IP from downloading it again (example below). Since you are already using the php script to detect the download, you could simply add (assuming MySQL) a Mysql query such as: $result = mysql_query('select dt.downloads, ip.ip_address from downloads_table dt RIGHT JOIN downloads_ip ip ON ip.track_id = "% your track id%" AND ip.ip_address = "'.$_SERVER ['REMOTE_ADDRESS'].'" where dt.track_id = "%your track id%"'); $results = mysql_fetch_array($result); if(($results['downloads'] <= 150) && (empty($results ['ip_address']))) { mysql_query('INSERT INTO downloads_ip (track_id,ip_address) VALUES ("%track_id%","'.$_SERVER['REMOTE_ADDRESS'].'")'); // insert IP into downloads_ip table mysql_query('UPDATE downloads_table SET downloads = downloads + 1 WHERE track_id = "%track_id%" LIMIT 1'); // update the count of the downloads // do download here } elseif (!empty($results['ip_address'])) { echo 'you have already downloaded this track...'; } else { echo 'this track is no longer available for download'; } (note I haven't checked the code, but it should give you a quick example of how you can keep track of this) Hope this helps, and if you have any questions just let me know. Take care, Mike :o) "My command is this: Love each other as I
have loved you."                         John 15:12
-----------------------
Oh my.. thank you for that. Karl DeSaulniers Design Drumm http://designdrumm.com
Karl DeSaulniers Design Drumm http://designdrumm.com --PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Karl DeSaulniers Design Drumm http://designdrumm.com

« previous php.db (#47204) next »