Anti-leeching script problem on Firefox

This is a discussion on "Anti-leeching script problem on Firefox" within the PHP Forum section. This forum, and the thread "Anti-leeching script problem on Firefox are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack (2) Thread Tools
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old Feb 10th, 2007, 03:39
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 233
Thanks: 4
Thanked 0 Times in 0 Posts
Anti-leeching script problem on Firefox

The code below comes from an excellent anti-leeching script- Download Sentinel ++

It's designed to allow people to download files using temporary links. As it's written, it forces files to be downloaded, but I need it to play files. (I'm hosting a bunch of wma files and I want to prevent bulk downloading.) I've modified the script so that the Content-Disposition is inline - and it works for images, and it works for wma files when using IE. But when using Firefox, it's still forcing downloading of wma files.

If anyone can spot anything that might be causing this, I'd be most grateful for the help!

You can see it in action at http://stickpuppy.com/dsplus/mplus.php - click on the amazed.png link to see it work, expand one of the year folders and click a wma file to see it fail (in FF).

PHP: Select all

function DownLoadFile($fil,$p)
{
    if (
connection_status()!=0) return(FALSE);
    
    
$extension strtolower(substr(strrchr($fn"."), 1)); 
    switch(
$extension){ 
    case 
"asf"$type "video/x-ms-asf"; break; 
    case 
"avi"$type "video/x-msvideo"; break; 
    case 
"exe"$type "application/octet-stream"; break; 
    case 
"mov"$type "video/quicktime"; break; 
    case 
"mp3"$type "audio/mpeg"; break; 
    case 
"mpg"$type "video/mpeg"; break; 
    case 
"mpeg"$type "video/mpeg"; break; 
    case 
"rar"$type "encoding/x-compress"; break; 
    case 
"txt"$type "text/plain"; break; 
    case 
"wav"$type "audio/wav"; break; 
    case 
"wma"$type "audio/x-ms-wma"; break; 
    case 
"wmv"$type "video/x-ms-wmv"; break; 
    case 
"zip"$type "application/x-zip-compressed"; break; 
    default: 
$type "application/force-download"; break; 
    } 
    
    
$fn basename($fil);
    
header("Cache-Control: no-store, no-cache, must-revalidate");
    
header("Cache-Control: post-check=0, pre-check=0"false);
    
header("Pragma: no-cache");
    
header("Expires: ".gmdate("D, d M Y H:i:s"mktime(date("H")+2date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
    
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
    
header("Content-Transfer-Encoding: binary\n");
    
header('Content-Type: $type');
    
    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'$fnsubstr_count($fn'.') - 1);
        
header("Content-Disposition: inline; filename=\"$iefilename\"");
    } 
    else 
    {
        
header("Content-Disposition: inline; filename=\"$iefilename\"");
    }
    
    
header("Accept-Ranges: bytes");
    
    
$range 0// default to begining of file
    
$speed DS_SPEED//  speed in kb/s
    
$size=filesize($fil);
    
    
//check if http_range is set. If so, change the range of the download to complete.
    
if(isset($_SERVER['HTTP_RANGE'])) 
    {
        list(
$a$range)=explode("=",$_SERVER['HTTP_RANGE']);
        
str_replace($range"-"$range);
        
$size2=$size-1;
        
$new_length=$size-$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);
    }
    
    
//check to ensure it is not an empty file so the feof does not get stuck in an infinte loop.
    
if ($size == sendToBrowser('Zero byte file! Aborting download');
    
set_magic_quotes_runtime(0); // in case someone has magic quotes on. Which they shouldn't as good practice.
    // we should check to ensure the file really exits to ensure feof does not get stuck in an infite loop, but we do so earlier on, so no need here.
    
$fp=fopen("$fil","rb");
    
    
//go to the start of missing part of the file
    
fseek($fp,$range);
    
    
//start  download
    
while(!feof($fp) and (connection_status()==0))
    {
        
//change time limit so big files do not get cut off with a timeout.
        
set_time_limit(0);
        print(
fread($fp,1024*$speed));
        
flush();
        
ob_flush();
        
sleep(1);
    }
    
fclose($fp);
    
    if (
DS_DLON ==1writeLog($p,$fil); // Txt file detail logging.
    
if (DS_COUNTON == 1countLog($fil); // Text file qty logging.
    
if (DB_ON == 1dbLog($fil); // Database qty logging.
        
    
return((connection_status()==0) and !connection_aborted());

Reply With Quote

Reply

Tags
anti leeching, firefox, leeching, mime, wma

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.webforumz.com/php-forum/20041-anti-leeching-script-problem-on-firefox.htm
Posted By For Type Date
Problems with PHP file upload script (1 file) - WebHostingTalk Forums This thread Refback Apr 18th, 2007 19:24
Problems with PHP file upload script (1 file) This thread Refback Apr 18th, 2007 18:10

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anti SQL Injection Functions spinal007 Classic ASP 5 Mar 7th, 2008 10:15
best free internet security/anti virus? unitedcraig Webforumz Cafe 28 Dec 15th, 2007 00:31
Best anti-leech script for hide url basketmen PHP Forum 4 Sep 26th, 2007 01:36
Java script entities and firefox hitec JavaScript Forum 1 Aug 11th, 2007 13:25
Javascript - Anti browser checking satimis JavaScript Forum 7 Aug 8th, 2007 15:43


All times are GMT. The time now is 06:42.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43