Форум: Форум PHPФорум ApacheФорум Регулярные ВыраженияФорум MySQLHTML+CSS+JavaScriptФорум FlashРазное
Новые темы: 0000000
Самоучитель PHP 5 / 6 (3 издание). Авторы: Кузнецов М.В., Симдянов И.В. PHP. Практика создания Web-сайтов (второе издание). Авторы: Кузнецов М.В., Симдянов И.В. PHP на примерах (2 издание). Авторы: Кузнецов М.В., Симдянов И.В. MySQL на примерах. Авторы: Кузнецов М.В., Симдянов И.В. Программирование. Ступени успешной карьеры. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

Форум PHP

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум Структурный форум

тема: Помогите с классом !
 
 автор: Inviseble_Demon   (20.12.2008 в 16:12)   письмо автору
 
 

Здраствуйте

Помогите передать переменную классу ПЛЗ !

сам кла

<?php

class Curl {
    var 
$curl;
        var 
$manual_follow;
        var 
$redirect_url;
    var 
$_USERAGENTS "";
    var 
$_USERAGENT "";
    var 
$proxy 'mwcp.selfip.com:3128';
    var 
$_COOKIE_FILE "./cookie/curl.cookie";

    function 
Curl() {
        global 
$CONF;

        
$this->_USERAGENTS explode("\n"file_get_contents('./stat/useragents.txt'));
        
$this->changeUA();

        
$this->curl curl_init();
        
curl_setopt($this->curlCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($this->curlCURLOPT_USERAGENT'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5'); //$this->_USERAGENT
        
curl_setopt($this->curlCURLOPT_SSL_VERIFYPEERfalse);
        
curl_setopt($this->curlCURLOPT_AUTOREFERERtrue);
            
curl_setopt($this->curlCURLOPT_HEADERtrue);
        if (
$this->proxycurl_setopt($this->curlCURLOPT_PROXY$this->proxy);
              
$this->setRedirect();
    }

    function 
putrealCookies($get) {
        
$eee=$this->check_cookie($getfile_get_contents($this->_COOKIE_FILE));
        
$h=fopen($this->_COOKIE_FILE,'w+');
                @
fwrite($h$eee);
                @
fclose($h);
        
        
#file_put_contents($this->_COOKIE_FILE, $this->check_cookie($get, file_get_contents($this->_COOKIE_FILE)));
        
        
        
        
    
}

    function 
getrealCookies() {
        return 
file_get_contents($this->_COOKIE_FILE);
    }


    
//парсим курловый файл с кукисами
    
function parseCookies($file)
    {
            
$result = array();
        
$data explode("\r\n"file_get_contents($file));
            for (
$x=0$x<count($data); $x++) {
                
$line trim($data[$x]);
                if ((
$line == '') || ($line == '#')) continue;
                
$parts explode("\t"$line);
                if (
count($parts) != 7) continue;
                list(
$domain, , $path$secure$expires$name$value) = $parts;
                
$secure = ($secure == 'TRUE');
                
$expires = ($expires == 'session') ? null : (int)$expires;
                
//$this->set_cookie($domain, $path, $name, $value, $secure, $expires);
            //$result[$name] = $value;
            
$result .= $name."=".$value.";";
            }
            return 
$result;
    }

    
//вытащить куки
    
function check_cookie($get$cookie)
    {
        
preg_match_all("#Set-Cookie: ([^;]*;)#i"$get$cookies);
        if(
count($cookies[1]) > 0) {
            foreach(
$cookies[1] as $str_cookie) {
                
$str_cookie_item explode("="$str_cookie);
                if(
preg_match("#".$str_cookie_item[0]."=([^;]*;)#i"$cookie,$matches)) {
                        
$cookie preg_replace("#".$str_cookie_item[0]."=([^;]*;)#i"$str_cookie$cookie);
                    }
                    else 
$cookie .= $str_cookie;
            }
        }
        return 
$cookie;
    }

    
//переключение юзер агента
    
function changeUA()
    {
        
$this->_USERAGENT $this->getUA();
    }

    
//получение случайного юзерагента
    
function getUA()
    {
        return 
trim($this->_USERAGENTS[rand(0count($this->_USERAGENTS)-1)]);
    }

    
//очистка куков
    
function clearCookie()
    {
        
//@unlink($this->_COOKIE_FILE);
        #file_put_contents($this->_COOKIE_FILE, "");
        
        
$h=fopen($this->_COOKIE_FILE,'w+');
                @
fwrite($h,'');
                @
fclose($h);

    }

    function 
getInstance() {
        static 
$instance;
        if (!isset(
$instance)) {
            
$curl =& new Curl;
            
$instance = array($curl);
        }
        return 
$instance[0];
    }

    function 
setTimeout($connect$transfer) {
        
curl_setopt($this->curlCURLOPT_CONNECTTIMEOUT$connect);
        
curl_setopt($this->curlCURLOPT_TIMEOUT$transfer);
    }

    function 
getError() {
        return 
curl_errno($this->curl) ? curl_error($this->curl) : false;
    }

    function 
disableRedirect() {
        
$this->setRedirect(false);
    }

    function 
setRedirect($enable true) {
        if (
$enable) {
            
$this->manual_follow curl_setopt($this->curlCURLOPT_FOLLOWLOCATIONtrue);
        } else {
            
curl_setopt($this->curlCURLOPT_FOLLOWLOCATIONfalse);
            
$this->manual_follow false;
        }
    
$this->manual_follow true;
    }

    function 
getHttpCode() {
        return 
curl_getinfo($this->curlCURLINFO_HTTP_CODE);
    }

    function 
auth($user$pass) {
        
curl_setopt($this->curlCURLOPT_USERPWD"$user:$pass");
    }

    function 
makeQuery($data) { 
        if (
is_array($data)) {
            
$fields = array();
            foreach (
$data as $key => $value) {
                 
$fields[] = $key '=' urlencode($value);
            }
            
$fields implode('&'$fields);
        } else {
            
$fields $data;
        }

        return 
$fields;
    }
    
    
// FOLLOWLOCATION manually if we need to
    
function maybeFollow($page) {
        
$page2 $page;
            if (
strpos($page"\r\n\r\n") !== false) {
                list(
$headers$page) = explode("\r\n\r\n"$page2);
            }

        echo 
"<br><br><br>Cookie start---------<br>".$this->check_cookie($getfile_get_contents($this->_COOKIE_FILE))."<br>------Cookie End<br><br><br>";
        echo 
$page2;
        
            
$this->putrealCookies($headers);

            
$code $this->getHttpCode();
            if (
$code 300 && $code 310) {
                
preg_match("#Location: ?(.*)#i"$headers$match);
                
$this->redirect_url trim($match[1]);

            if (
$this->manual_follow) {
            
            echo 
"<br><br><br>=====Redirect URL:=======<br><br>".$this->get($this->redirect_url)."<br>============<br><br><br>";
            
                    return 
$this->get($this->redirect_url);
                }
            else return 
$page2;
        } else {
                
$this->redirect_url '';
            }

        return 
$page;
    }
    
    function 
post($url$data) {
        
$fields $this->makeQuery($data);
        
        
curl_setopt($this->curlCURLOPT_COOKIE$this->getrealCookies());
        
curl_setopt($this->curlCURLOPT_URL$url);
        
curl_setopt($this->curlCURLOPT_POSTtrue);
        
curl_setopt($this->curlCURLOPT_POSTFIELDS$fields);
        
$page curl_exec($this->curl);
            
        
$error curl_errno($this->curl);    
        if (
$error != CURLE_OK || empty($page)) {
            return 
false;
        }

        
curl_setopt($this->curlCURLOPT_POSTfalse);
        
curl_setopt($this->curlCURLOPT_POSTFIELDS'');

        
$this->putrealCookies($page);

        return 
$this->maybeFollow($page);
    }
    
    function 
get($url$data null) {
            if (!
is_null($data)) {
                
$fields $this->makeQuery($data);
                
$url .= '?' $fields;
            }

        
curl_setopt($this->curlCURLOPT_COOKIE$this->getrealCookies());
        
curl_setopt($this->curlCURLOPT_URL$url);
        
$page curl_exec($this->curl);
        
        
$error curl_errno($this->curl);

        if (
$error != CURLE_OK || empty($page)) {
            return 
false;
        }

        
$this->putrealCookies($page);
        
        return 
$this->maybeFollow($page);
    }
}

?>



сейчас в класе прописоно статично !
Как зделать чтобы проксик передовался с этого скрипта ?


<?php

ini_set
("max_execution_time""0");
ignore_user_abort(0);
$proxy 'mwcp.selfip.com:3128'// Это надо передать ! В клас curl.class.php !!!

require_once "./classes/curl.class.php";
require_once 
"./classes/forms.class.php";
require_once 
"./classes/htmlparser.class.php";


    
$browser = new forms();
    
$curl =& new Curl();
    
$curl->proxy "mwcp.selfip.com:3128";
    
$curl->setTimeout(ASP_CONNECT_TIMEOUTASP_TRANSFER_TIMEOUT);
    
$curl->_COOKIE_FILE './cookie/curl.cookie';


    
$page $curl->get('http://proverim.net/ip.php');
    
//echo $page;    

?>


Помогите очень надо !

  Ответить  
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования