www.webdeveloper.com
Results 1 to 5 of 5

Thread: Class PHP

  1. #1
    Join Date
    Apr 2014
    Posts
    5

    Class PHP

    I try this

    Code:
    <?php
    
    $meuObjeto = new Torrent();
    
    $meuObjeto->scrape("$r"); 
    
    ?>

    and this

    Code:
    <?php
    
    $meuObjeto = new Torrent();
    
    $meuObjeto->scrape("udp://fopen.demonii.com", 7C90CFEE93DE8C4FA04526DAA5CE530ADFB8DF6E); 
    
    ?>

    not sucess...

  2. #2
    Join Date
    Apr 2014
    Posts
    5
    How use this class ?

    PHP Code:
    <?php
     
    class Torrent
    {
        public function 
    scrape(array $announce = [ ] , $hash_info null)
        {
     
            
    $r = [
                
    'seeders'  => ,
                
    'leechers' => 0
            
    ];
     
            foreach ( 
    $announce as $an ) {
     
                
    $d get_remote_peers($an $hash_info);
     
                if ( isset(
    $d['seeders']) ) {
                    
    $r['seeders'] += $d['seeders'];
                }
     
                if ( isset(
    $d['leechers']) ) {
                    
    $r['leechers'] += $d['leechers'];
                }
            }
     
            return 
    $r;
        }
     
    }
     
     
    /**
     * Gets amout of remote tracker peers. May be recursivity.
     *
     * @param string $url Announce url of request
     * @param string $info_hash Info-hash of torrent to be parsed
     * @param string $method Method of gathering amount of peers. May be scrape or announce. Default 'scrape'. If scrape fails, recursivety swithes to announce and executes again.
     *
     * @return array Result array ('tracker','seeders','leechers','state');
     */
    function get_remote_peers($url $info_hash $method 'scrape')
    {
     
        if ( 
    $method == "announce" ) {
            
    $get_params = array(
                
    "info_hash"  => pack("H*" $info_hash) ,
                
    "peer_id"    => "-UT1820-5dmPcUOYGnrx" ,
                
    "port"       => rand(10000 65535) ,
                
    "uploaded"   => ,
                
    "no_peer_id" => ,
                
    "downloaded" => ,
                
    "compact"    => ,
                
    "left"       => ,
                
    "numwant"    => 9999
            
    );
        } else {
            
    $urlorig    $url;
            
    $url        str_replace('announce' 'scrape' $url);
            
    $get_params = array(
                
    "info_hash" => pack("H*" $info_hash)
            );
        }
     
     
        
    $urlInfo   = @parse_url($url);
        
    $http_host $urlInfo['host'];
        
    $http_port getUrlPort($urlInfo);
        
    $scheme    $urlInfo['scheme'];
     
        if ( 
    $http_port === ) {
            return array( 
    'tracker' => $http_host 'state' => 'failed:no_port_detected' 'method' => "$scheme:$method'remote_method' => 'N/A' );
        }
     
        
    $http_path          $urlInfo['path'];
        
    $get_request_params = @explode('&' $urlInfo['query']);
     
        
    $new_get_request_params false;
        foreach ( 
    array_filter($get_request_params) as $array_value ) {
            list(
    $key $value) = explode('=' $array_value);
            
    $new_get_request_params[$key] = $value;
        }
     
        if ( !
    $new_get_request_params ) {
            
    $new_get_request_params = array();
        }
        
    // Params gathering complete
     
        // Creating params
        
    $http_params = @http_build_query(@array_merge($new_get_request_params $get_params));
        
    $opts        = array(
            
    $scheme => array(
                
    'method'  => 'GET' ,
                
    'header'  => 'User-Agent: uTorrent/1820' ,
                
    'timeout' => 3
                
    //'Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2',
            
    )
        );
    Last edited by NogDog; 04-21-2014 at 02:31 PM. Reason: changed code tag to php tag and added closing tag

  3. #3
    Join Date
    Apr 2014
    Posts
    5
    PHP Code:
    $req_uri $scheme '://' $http_host ':' $http_port $http_path . ($http_params '?' $http_params '');
     
     
        if ( 
    $scheme == 'udp' && $method == 'scrape' ) {
     
            
    $transaction_id mt_rand(65535);
            
    $fp             = @fsockopen($scheme '://' $http_host $http_port $errno $errstr); //sockets only
            
    if ( !$fp ) {
                return array( 
    'tracker' => $http_host 'state' => 'failed:timeout' 'method' => "$scheme:$method'remote_method' => 'socket' );
            }
            
    stream_set_timeout($fp 3);
     
            
    $current_connid "\x00\x00\x04\x17\x27\x10\x19\x80";
     
            
    //Connection request
            
    $packet $current_connid pack("N" 0) . pack("N" $transaction_id);
            
    fwrite($fp $packet);
     
            
    //Connection response
            
    $ret fread($fp 16);
            if ( 
    strlen($ret) < ) {
                return 
    get_remote_peers($urlorig $info_hash "announce");
            }
            if ( 
    strlen($ret) < 16 ) {
                return array( 
    'tracker' => $http_host 'state' => 'failed:invalid_udp_packet' 'method' => "$scheme:$method'remote_method' => 'socket' );
            }
            
    $retd unpack("Naction/Ntransid" $ret);
            if ( 
    $retd['action'] != || $retd['transid'] != $transaction_id ) {
                return array( 
    'tracker' => $http_host 'state' => 'failed:invalid_udp_response' 'method' => "$scheme:$method'remote_method' => 'socket' );
            }
            
    $current_connid substr($ret 8);
     
            
    //Scrape request
            
    $packet $current_connid pack("N" 2) . pack("N" $transaction_id) . pack('H*' $info_hash);
            
    fwrite($fp $packet);
            
    //Scrape response
            
    $readlength 20//8 + (12);
            
    $ret        fread($fp $readlength);
            if ( 
    strlen($ret) < ) {
                return 
    get_remote_peers($urlorig $info_hash "announce");
            }
            if ( 
    strlen($ret) < ) {
                array( 
    'tracker' => $http_host 'state' => 'failed:invalid_udp_packet' 'method' => "$scheme:$method'remote_method' => 'socket' );
            }
            
    $retd unpack("Naction/Ntransid" $ret);
            
    // Todo check for error string if response = 3
            
    if ( $retd['action'] != || $retd['transid'] != $transaction_id ) {
                array( 
    'tracker' => $http_host 'state' => 'failed:invalid_udp_response' 'method' => "$scheme:$method'remote_method' => 'socket' );
            }
            if ( 
    strlen($ret) < $readlength ) {
                return array( 
    'tracker' => $http_host 'state' => 'failed:invalid_udp_packet' 'method' => "$scheme:$method'remote_method' => 'socket' );
            } 
    Last edited by NogDog; 04-21-2014 at 02:32 PM. Reason: added php tags around code

  4. #4
    Join Date
    Jan 2014
    Posts
    187
    A class is a collection of variables and functions working with these variables. Variables are defined by var and functions by function. A class is defined using the following syntax:
    <?php
    class Cart {
    var $items; // Items in our shopping cart

    // Add $num articles of $artnr to the cart

    function add_item($artnr, $num) {
    $this->items[$artnr] += $num;
    }

    // Take $num articles of $artnr out of the cart

    function remove_item($artnr, $num) {
    if ($this->items[$artnr] > $num) {
    $this->items[$artnr] -= $num;
    return true;
    } elseif ($this->items[$artnr] == $num) {
    unset($this->items[$artnr]);
    return true;
    } else {
    return false;
    }
    }
    }
    ?>

  5. #5
    Join Date
    May 2003
    Posts
    599
    Quote Originally Posted by alanps2012 View Post
    I try this

    Code:
    <?php
    
    $meuObjeto = new Torrent();
    
    $meuObjeto->scrape("udp://fopen.demonii.com", 7C90CFEE93DE8C4FA04526DAA5CE530ADFB8DF6E); 
    
    ?>
    not sucess...
    The first problem I see is that the first param of the "scrape()" function is looking for an array and you are passing a string...the second arguement, you are passing a string, but not enclosed in quotes. I have not tested this at all...just throwing this out, but try:

    PHP Code:
    $meuObjeto = new Torrent();
    $meuObjeto->scrape(array("$url1","$url2"), '7C90CFEE93DE8C4FA04526DAA5CE530ADFB8DF6E'); 
    Make sure to enable error reporting and display and some of the errors may become more obvious.
    We do precision guesswork

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17530 seconds
  • Memory Usage 2,948KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates