| Здраствуйте
Помогите передать переменную классу ПЛЗ !
сам кла
<?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->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_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->curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->curl, CURLOPT_AUTOREFERER, true);
curl_setopt($this->curl, CURLOPT_HEADER, true);
if ($this->proxy) curl_setopt($this->curl, CURLOPT_PROXY, $this->proxy);
$this->setRedirect();
}
function putrealCookies($get) {
$eee=$this->check_cookie($get, file_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(0, count($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->curl, CURLOPT_CONNECTTIMEOUT, $connect);
curl_setopt($this->curl, CURLOPT_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->curl, CURLOPT_FOLLOWLOCATION, true);
} else {
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, false);
$this->manual_follow = false;
}
$this->manual_follow = true;
}
function getHttpCode() {
return curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
}
function auth($user, $pass) {
curl_setopt($this->curl, CURLOPT_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", $page, 2);
}
echo "<br><br><br>Cookie start---------<br>".$this->check_cookie($get, file_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->curl, CURLOPT_COOKIE, $this->getrealCookies());
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_POST, true);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields);
$page = curl_exec($this->curl);
$error = curl_errno($this->curl);
if ($error != CURLE_OK || empty($page)) {
return false;
}
curl_setopt($this->curl, CURLOPT_POST, false);
curl_setopt($this->curl, CURLOPT_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->curl, CURLOPT_COOKIE, $this->getrealCookies());
curl_setopt($this->curl, CURLOPT_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_TIMEOUT, ASP_TRANSFER_TIMEOUT);
$curl->_COOKIE_FILE = './cookie/curl.cookie';
$page = $curl->get('http://proverim.net/ip.php');
//echo $page;
?>
|
Помогите очень надо ! | |