Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need really help with this code

    hi @ all
    Need help with php script..its a download script
    when i use it it cant download any files couse the script cant get the download file size.
    I tryed really lot things.
    I am thinking that the problem is
    on "$header = getallheaders();"
    when i remove that i can download with a download manager
    but when i try to start the download without a downoad manager its just waiting...
    anyway here is the code..hope someone can help me:
    as far readed from php pages the problem is that the php module is not installed at my host..
    is there another way to let this code work..? or maybe something like this?

    PHP Code:
    <?php 
    require './functions.php'
    register_shutdown_function('bye_bye'); 
    ReadConfig ('DEVINFO, MAIN, WHITELIST, BLACKLIST, REFLIST'); 
    header ("Expires: Tue, 1 Jan 1980 00:00:00 GMT"); 
    header ("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 
    header ("Cache-Control: no-store, no-cache, must-revalidate"); 
    header ("Cache-Control: post-check=0, pre-check=0"false); 
    header ("Pragma: no-cache"); 
    header ("X-Powered-By: Antileech"); 
    $IP GetIP(); 
    $whitelisted WhiteList($IP); 
    if (!
    $whitelisted && BlackList($IP)) { 
        
    Message ('You were added to blacklist. Go **** yourself...'$MAIN['url']); 

    if (!
    $whitelisted && !CheckReferer()) { 
        
    Message ('This page is only avaliable from the '.$MAIN['url'].' site, where you\'re being redirected...'$MAIN['url']); 

    mysql_connect($MAIN['db_address'], $MAIN['db_username'], $MAIN['db_password']); 
    mysql_select_db($MAIN['db_database']); 

    ClearTimeouted(); 

    $return GetParams(); 
    if (
    sizeof($return) != 2) { 
        
    Message ('Wrong query!'); 

    $session $return[0]; 

    if (!empty(
    $MAIN['maxtotalthreads'])) { 
        
    $Query "SELECT SUM(threads) AS `total` FROM ".$MAIN['db_table']; 
        
    $Res mysql_query($Query); 
        list(
    $total) = mysql_fetch_array($Res); 
        if (
    $total >= $MAIN['maxtotalthreads']) { 
            
    Message ('Unfortunately, the server load is too high at the moment. This server can handle only '.$MAIN['maxtotalthreads'] .' threads simultaneous. Please, try again later.'); 
        } 


    $Query "SELECT SUM(threads) FROM ".$MAIN['db_table']." WHERE ip = '".$IP."'"
    $Result mysql_query($Query); 
    if (
    mysql_num_rows($Result)) { 
        list(
    $threads) = mysql_fetch_array($Result); 
        if (
    $threads >= $MAIN['maxthreadspersession']) { 
            
    Message ('You cannot download more than '.$MAIN['maxthreadspersession'].' threads at the same time!'$MAIN['url']); 
        } 


    $Query "SELECT * FROM ".$MAIN['db_table']." WHERE session = '".addslashes($session)."' AND ip = '".$IP."'"
    $Result mysql_query($Query); 
    if (!
    mysql_num_rows($Result)) { 
        
    Message ('Your session expired or you specified wrong session name.'$MAIN['url']); 

    $info mysql_fetch_assoc($Result); 

    $Query "UPDATE ".$MAIN['db_table']." SET threads = threads + 1 WHERE session = '".addslashes($session)."'"
    $Result mysql_query($Query); 
    $is_increased true

    $fullpath $MAIN['filepath'].$info['category'].'/'.$info['file']; 
    $size filesize($fullpath); 

    $fp fopen($fullpath'r'); 
    header ('Accept-Ranges: bytes'); 
    header ('Content-Type: application/force-download'); 
    header ('Connection: close'); 

    $header getallheaders(); 
    if (isset(
    $header['Range'])) { 
        
    header('HTTP/1.0 206 Partial Content'); 
        
    $range $header['Range']; 
        
    $r explode('='$range); 
        list(
    $from) = explode('-'$r[1]); 
        
    $length $size $from
        
    $s_start $size $length
        
    $s_end $size 1
        
    fseek($fp$s_start); 
        
    header ('Content-Range: bytes '.$s_start.'-'.$s_end.'/'.$size); 
        
    header ('Content-Length: '.$length); 
    } else { 
        
    header('Content-Length: '$size); 

    set_time_limit(0); 
    ob_implicit_flush(true); 
    if (empty(
    $MAIN['maxkbps'])) { 
        while (!
    feof($fp)) { 
            print (
    fread($fp10240)); 
            if (
    connection_aborted()) { 
                break; 
            } 
        }    
    } else { 
        
    $koef 10
        
    $readlen intval(1024 $MAIN['maxkbps'] / $koef); 
        
    $waittime intval(1000000 $koef); 
        while (!
    feof($fp)) { 
            if (
    connection_aborted()) { 
                break; 
            } 
            print (
    fread($fp$readlen)); 
            
    usleep($waittime); 
        } 

    fclose($fp); 
    ?>

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Do you use that Content-Length header?
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the script uses the getallheaders function..
    but this only useable when php is installed as module on apache
    wich is not at my host.
    so i need something else instead of this thats the scripts works with my site..

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    My previous post was about this:
    when i use it it cant download any files couse the script cant get the download file size.
    You can add:
    PHP Code:
    header('Content-Length:' filesize($file)); 
    BTW getallheaders() lists sent headers and doesn't set any.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #5
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    tryed to add...dont work
    is there not a code wich i can use instead of "getallheaders"
    but a code wich dont need the php as module for apache

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    And we need really help with you to read our posting guidelines
    http://www.codingforums.com/postguide.htm
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You can write your own functions/class to replace getallheaders() if it doesn't work for you or use headers_list() (PHP5) or write code without the need of checking what headers are sent.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can u give me a example how u mean "u own functions/class"
    dont be really good at such things...
    when i remove headers the download is only working with use of a download manager... but i cant say to all boardmembers (have a board and need this for that) go and install all download managers..

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could use a class like this (something very simple):
    PHP Code:
    class header
    {
        var 
    $headers = array();
        
        function 
    send($header)
        {
            
    $this->headers[] = $header;
            return 
    header($header);
        }
        
        function 
    getallheaders()
        {
            return 
    $this->headers;
        }
    }
    $header = new header;
    $header->send('Content-Type: text/css');
    // ...
    var_dump($header->getallheaders()); 
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #10
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    should i modify the code like this?
    if wrong can u show me on this code?


    PHP Code:
    <?php  
    require './functions.php';  
    register_shutdown_function('bye_bye');  
    ReadConfig ('DEVINFO, MAIN, WHITELIST, BLACKLIST, REFLIST');  
    header ("Expires: Tue, 1 Jan 1980 00:00:00 GMT");  
    header ("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");  
    header ("Cache-Control: no-store, no-cache, must-revalidate");  
    header ("Cache-Control: post-check=0, pre-check=0"false);  
    header ("Pragma: no-cache");  
    header ("X-Powered-By: Antileech");  
    $IP GetIP();  
    $whitelisted WhiteList($IP);  
    if (!
    $whitelisted && BlackList($IP)) {  
        
    Message ('You were added to blacklist. Go **** yourself...'$MAIN['url']);  
    }  
    if (!
    $whitelisted && !CheckReferer()) {  
        
    Message ('This page is only avaliable from the '.$MAIN['url'].' site, where you\'re being redirected...'$MAIN['url']);  
    }  
    mysql_connect($MAIN['db_address'], $MAIN['db_username'], $MAIN['db_password']);  
    mysql_select_db($MAIN['db_database']);  

    ClearTimeouted();  

    $return GetParams();  
    if (
    sizeof($return) != 2) {  
        
    Message ('Wrong query!');  
    }  
    $session $return[0];  

    if (!empty(
    $MAIN['maxtotalthreads'])) {  
        
    $Query "SELECT SUM(threads) AS `total` FROM ".$MAIN['db_table'];  
        
    $Res mysql_query($Query);  
        list(
    $total) = mysql_fetch_array($Res);  
        if (
    $total >= $MAIN['maxtotalthreads']) {  
            
    Message ('Unfortunately, the server load is too high at the moment. This server can handle only '.$MAIN['maxtotalthreads'] .' threads simultaneous. Please, try again later.');  
        }  
    }  

    $Query "SELECT SUM(threads) FROM ".$MAIN['db_table']." WHERE ip = '".$IP."'";  
    $Result mysql_query($Query);  
    if (
    mysql_num_rows($Result)) {  
        list(
    $threads) = mysql_fetch_array($Result);  
        if (
    $threads >= $MAIN['maxthreadspersession']) {  
            
    Message ('You cannot download more than '.$MAIN['maxthreadspersession'].' threads at the same time!'$MAIN['url']);  
        }  
    }  

    $Query "SELECT * FROM ".$MAIN['db_table']." WHERE session = '".addslashes($session)."' AND ip = '".$IP."'";  
    $Result mysql_query($Query);  
    if (!
    mysql_num_rows($Result)) {  
        
    Message ('Your session expired or you specified wrong session name.'$MAIN['url']);  
    }  
    $info mysql_fetch_assoc($Result);  

    $Query "UPDATE ".$MAIN['db_table']." SET threads = threads + 1 WHERE session = '".addslashes($session)."'";  
    $Result mysql_query($Query);  
    $is_increased true;  

    $fullpath $MAIN['filepath'].$info['category'].'/'.$info['file'];  
    $size filesize($fullpath);  

    class 
    header 

        var 
    $headers = array(); 
         
        function 
    send($header
        { 
            
    $this->headers[] = $header
            return 
    header($header); 
        } 
         
        function 
    getallheaders() 
        { 
            return 
    $this->headers
        } 

    $header = new header
    $header->send('Content-Type: text/css'); 
    // ... 
    var_dump($header->getallheaders());

  • #11
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its not working like i tryed.sry i know i am noob in such things..

  • #12
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You should add the "$header = new header;" line before any headers and change all "header(" function calls into
    "$header->send(".
    the
    PHP Code:
    $header->send('Content-Type: text/css'); 
    // ... 
    var_dump($header->getallheaders()); 
    Was just an example. You don't have to use it anywhere.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #13
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    really thx for your help but i couldt get it work...
    maybe i making something false but now i am trying since 3 days to get this work on my server...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •