28, May 2012

allow only one file for each IP - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: allow only one file for each IP
« previous next »
Pages: [1] 2 Print
Instabuck - The easy way to sell digital products online

Author Topic: allow only one file for each IP  (Read 4833 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« on: Jul 05, 2007, 11:45:18 pm »

Hi, I have this code and need to use "ignore_user_abort(true)" the right way:

$file addslashes($_SERVER['REQUEST_URI']);
$ip addslashes($_SERVER['REMOTE_ADDR']);
$dl false;


$sql sprintf("SELECT UNIX_TIMESTAMP(last_access) last_time FROM downloaded WHERE filepath = '%s' AND ipadres = '%s' ORDER BY last_access DESC"$file$ip);
$res mysql_query($sql);
if (
mysql_num_rows($res) > 0) {
	
$last_xs mysql_result($res0'last_time')+3600;
	
$now time();
	
if (
$last_xs $now) {
	
	
$dl true;
	

} else {
	
$dl true;
}

if (
$dl) {
	
mysql_query(sprintf("REPLACE downloaded SET filepath = '%s', ipadres = '%s', last_access = NOW()"$file$ip));
	
ignore_user_abort(true);
	
dl_file_resume(ltrim($file'/')); // this function is just a download function with resume abbility
	
mysql_close($cs_conn);
} else {
	
header('HTTP/1.0 503 Service Unavailable');
}
exit;
?>


what do I need to do that it works for 100%

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Jul 06, 2007, 07:30:21 am »

What exactly do you want to do? Allow 1 download to the same file per hour?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Jul 06, 2007, 07:59:49 am »

yes for each user, I want to block multiple access for download clients.

I guess what I need to do is to update the record if the file download is finished...

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #3 on: Jul 06, 2007, 08:04:20 am »

with ignore_user_abort(true) you only have to delete the record in the end of the script

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Jul 06, 2007, 12:44:46 pm »

with ignore_user_abort(true) you only have to delete the record in the end of the script

will say I need to che4ck like this?

if (ignore_user_abort(true) == 1) {
  // delete teh record?
}

and this code at after the code where the output starts

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #5 on: Jul 06, 2007, 01:38:05 pm »

I don't think you need to check this, but the way you write it will work definately

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Jul 06, 2007, 02:15:20 pm »

I don't think you need to check this, but the way you write it will work definately

how to work without validation?

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #7 on: Jul 06, 2007, 02:41:33 pm »

There is no need for validation. The ignore_user_abort() is a directive.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #8 on: Jul 06, 2007, 03:46:16 pm »

There is no need for validation. The ignore_user_abort() is a directive.
this is what I don't understand, I need to use the code like this?

   

ignore_user_abort(true);
dl_file_resume(ltrim($file, '/'));
// code to delete the record

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #9 on: Jul 06, 2007, 04:43:05 pm »

Yes.

If you run the ignore_user_abort(true); command then the script wont stop until the process finishes.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #10 on: Jul 07, 2007, 02:00:55 pm »

Yes.

If you run the ignore_user_abort(true); command then the script wont stop until the process finishes.

so if I use the delete statement at the end after the download is finished. it should work because the user will not download the file again right?

Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #11 on: Jul 07, 2007, 02:02:20 pm »

but what if someone want to continue the download later? Sad

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #12 on: Jul 07, 2007, 02:40:50 pm »

Yes.

If you run the ignore_user_abort(true); command then the script wont stop until the process finishes.

so if I use the delete statement at the end after the download is finished. it should work because the user will not download the file again right?

It will work because even if the download corrupts the user will be able to download it again.


Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #13 on: Jul 07, 2007, 02:43:59 pm »

... hm, I'm still not sure if this will work with these download managers...

and what if the user need to download a CD (900 GB) and has a slow connection and need several attempts (using a DL manager) this way the use has  created x * 900GB as traffic...

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #14 on: Jul 07, 2007, 02:48:24 pm »

This wont work with download managers.

To make it work with a download manager you need to work it out more. Check this directive :

$_SERVER['HTTP_RANGE']

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #15 on: Jul 07, 2007, 02:51:20 pm »

This wont work with download managers.

To make it work with a download manager you need to work it out more. Check this directive :

$_SERVER['HTTP_RANGE']

I know I use this function to have this resume function:

Code:
<?php
function dl_file_resume($file){

    
//First, see if the file exists
    
if (!is_file($file)) { die("<b>404 File not found!</b>"); }
   
    
//Gather relevent info about file
    
$len filesize($file);
    
$filename basename($file);
    
$file_extension strtolower(substr(strrchr($filename,"."),1));
   
    
//This will set the Content-Type to the appropriate setting for the file
    
switch( $file_extension ) {
        case 
"exe"$ctype="application/octet-stream"; break;
        case 
"zip"$ctype="application/zip"; break;
        case 
"mp3"$ctype="audio/mpeg"; break;
        case 
"mpg":$ctype="video/mpeg"; break;
        case 
"avi"$ctype="video/x-msvideo"; break;
        default: 
$ctype="application/force-download";
    }
   
    
//Begin writing headers
    
header("Cache-Control:");
    
header("Cache-Control: public");
   
    
//Use the switch-generated Content-Type
    
header("Content-Type: $ctype");
    if (
strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
        
# workaround for IE filename bug with multiple periods / multiple dots in filename
        # that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
        
$iefilename preg_replace('/\./''%2e'$filenamesubstr_count($filename'.') - 1);
        
header("Content-Disposition: attachment; filename=\"$iefilename\"");
    } else {
        
header("Content-Disposition: attachment; filename=\"$filename\"");
    }
    
header("Accept-Ranges: bytes");
   
    
$size=filesize($file);
    
//check if http_range is sent by browser (or download manager)
    
if(isset($_SERVER['HTTP_RANGE'])) {
        list(
$a$range)=explode("=",$_SERVER['HTTP_RANGE']);
        
//if yes, download missing part
        
str_replace($range"-"$range);
        
$size2=$size-1;
        
$new_length=$size2-$range;
        
header("HTTP/1.1 206 Partial Content");
        
header("Content-Length: $new_length");
        
header("Content-Range: bytes $range$size2/$size");
    } else {
        
$size2=$size-1;
        
header("Content-Range: bytes 0-$size2/$size");
        
header("Content-Length: ".$size);
    }
    
//open the file
    
$fp=fopen("$file","rb");
    
//seek to start of missing part
    
fseek($fp,$range);
    
//start buffered download
    
while(!feof($fp)){
        
//reset time limit for big files
        
set_time_limit(0);
        print(
fread($fp,1024*8));
        
flush();
        
ob_flush();
    }
    
fclose($fp);
    exit;
}


Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #16 on: Jul 07, 2007, 02:53:12 pm »

Nick,

what I need to do is to limit the connections from the DL manager which downloads the file several time, of course not the whole one but almost Sad


I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #17 on: Jul 07, 2007, 03:09:26 pm »

So instead of using 5 concurrent connections it should allow 3?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #18 on: Jul 07, 2007, 03:15:42 pm »

So instead of using 5 concurrent connections it should allow 3?

1 or 2

is 5 a setting I can change on my server?

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #19 on: Jul 07, 2007, 03:21:28 pm »

You should do that yourself, by checking how many times the user entered the if(isset($_SERVER['HTTP_RANGE'])) {?> and I am not sure if this is going to work.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6882
Tags : php download Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] 2 Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: allow only one file for each IP
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 10:08:33 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.