php curl https не передаются параметры

Discussion in 'Песочница' started by Prog-t, 13 Apr 2016.

  1. Prog-t

    Prog-t New Member

    Joined:
    24 Nov 2015
    Messages:
    17
    Likes Received:
    2
    Reputations:
    0
    День добрый,использую класс для работы с curl
    Code:
    <?php
    //***************************************************//
    //                            //
    //         Class for cURL      //
    //  *********************************************  //
    //    Author: Stsepanchuk Ruslan              //
    //  *********************************************  //
    //  Blog: swblog.ru                  //
    //  //
    //***************************************************//
    
    class curl {
    
       var $ch;
       var $httpget = ''; 
       var $head = '';
       var $postparams = array (); 
       var $httpheader = array ();
       var $cookie = array ();
       var $proxy = '';
       var $proxy_user_data = '';
       var $verbose = 0;
       var $referer = '';
       var $autoreferer = 0;
       var $writeheader = '';
       var $agent = 'Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20100101 Firefox/23.0';
       var $url = ''; 
       var $followlocation = 1;
       var $returntransfer = 1;
       var $ssl_verifypeer = 0;
       var $ssl_verifyhost = 0;
       var $sslcert = '';
       var $sslkey = '';
       var $cainfo = '';
       var $cookiefile = '';
       var $timeout = 0;
       var $connect_time = 0;
       var $encoding = 'gzip,deflate'; 
       var $interface = '';
     
       function __construct (){
         $this->ch = curl_init();
         $this->set_httpheader(array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3','Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7'));
       }
     
       function get ($url){
         $this->url = $url;
         return $this->exec();
       }
     
       function post ($url, $postparams, $enctype = false){
         $this->url = $url;
       
         if (!$enctype) {
           $this->postparams = $postparams;
         }
         else {
           $this->postparams = array ();
           $params = explode("&", $postparams);
           for($i = 0; $i < count($params); $i++) {
             list($name, $value) = explode("=", $params[$i]);
             $this->postparams[$name] = $value;
           }
         }
       
         return $this->exec();
       }
     
       function set_httpget ($httpget){
         $this->httpget = $httpget;
       }
     
       function set_referer ($referer){
         $this->referer = $referer;
       }
     
       function set_autoreferer ($autoreferer){
         $this->autoreferer = $autoreferer;
       }
     
       function set_useragent ($agent){
         $this->agent = $agent;
       } 
     
       function set_cookie (){
         preg_match_all('/Set-Cookie: (.*?)=(.*?);/i', $this->head, $matches, PREG_SET_ORDER);
       
         for ($i = 0; $i < count($matches); $i++) {
           if ($matches[$i][2] == 'deleted') {
             $this->delete_cookie($matches[$i][1]);
           } else {
             $this->cookie[$matches[$i][1]] = $matches[$i][2];
           }
         } 
       }
     
       function add_cookie ($cookie){
         foreach ($cookie as $name => $value) {
           $this->cookie[$name] = $value;
         }
       }
     
       function delete_cookie ($name){
         if (isset($this->cookie[$name]))
           unset($this->cookie[$name]);
       }
     
       function get_cookie (){
         return $this->cookie;
       }
     
       function clear_cookie (){
         $this->cookie = array ();
       }
     
       function set_httpheader ($httpheader){
         $this->httpheader = $httpheader;
       }
     
       function clear_httpheader (){
         $this->httpheader = array ();
       }
     
       function set_head ($head){
         $this->head = $head;
       }
     
       function set_encoding ($encoding){
         $this->encoding = $encoding;
       } 
     
       function set_interface ($interface){
         $this->interface = $interface;
       }
    
       function set_writeheader ($writeheader){ 
         $this->writeheader = $writeheader;
       }
    
       function set_followlocation ($followlocation){
         $this->followlocation = $followlocation;
       }
    
       function set_returntransfer ($returntransfer){
         $this->returntransfer = $returntransfer;
       }
     
       function set_ssl_verifypeer ($ssl_verifypeer){
         $this->ssl_verifypeer = $ssl_verifypeer;
       }
     
       function set_ssl_verifyhost ($ssl_verifyhost){
         $this->ssl_verifyhost = $ssl_verifyhost;
       }
     
       function set_sslcert ($sslcert) {
         $this->sslcert = $sslcert;
       }
     
       function set_sslkey ($sslkey) {
         $this->sslkey = $sslkey;
       }
     
       function set_cainfo ($cainfo) {
         $this->cainfo = $cainfo;
       }
     
       function set_timeout ($timeout){
         $this->timeout = $timeout;
       }
     
       function set_connect_time ($connect_time){
         $this->connect_time = $connect_time;
       }
     
       function set_cookiefile ($cookiefile){
         $this->cookiefile = $cookiefile;
       }
    
       function set_proxy ($proxy){
         $this->proxy = $proxy;
       }
     
       function set_proxy_auth ($proxy_user_data){
         $this->proxy_user_data = $proxy_user_data;
       }
     
       function set_verbose ($verbose){
         $this->verbose = $verbose;
       }
     
       function get_error (){
         return curl_errno($this->ch);
       }
     
       function get_location (){
         $result = '';
       
         if (preg_match("/Location: (.*?)\r\n/is", $this->head, $matches)) {
           $result = end($matches);
         }
     
         return $result;
       }
     
       function get_http_state (){
         if (curl_getinfo($this->ch, CURLINFO_HTTP_CODE) == 200) {
           return true;
         } else {
           return false;
         }
       }
     
       function get_speed_download (){
         return curl_getinfo($this->ch, CURLINFO_SPEED_DOWNLOAD);
       }
     
       function get_content_type (){
         return curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
       }
     
       function get_url (){
         return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL);
       }
     
       function join_cookie() {
         $tcookie = array ();
         foreach ($this->cookie as $key => $value)
           $tcookie[] = "$key=$value";
         return join('; ', $tcookie);
       }
     
       function exec (){
         curl_setopt($this->ch, CURLOPT_USERAGENT, $this->agent);
         curl_setopt($this->ch, CURLOPT_AUTOREFERER, $this->autoreferer);
         curl_setopt($this->ch, CURLOPT_ENCODING, $this->encoding);
         curl_setopt($this->ch, CURLOPT_URL, $this->url);
         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION , $this->followlocation);
         curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,$this->returntransfer); 
         curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
         curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, $this->ssl_verifyhost);
         curl_setopt($this->ch, CURLOPT_HEADER, 1);
         curl_setopt($this->ch, CURLOPT_TIMEOUT, $this->timeout);
         curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $this->connect_time);
         curl_setopt($this->ch, CURLOPT_VERBOSE, $this->verbose);
         curl_setopt($this->ch, CURLOPT_POST, 0);
       
         if ($this->referer)
           curl_setopt($this->ch, CURLOPT_REFERER, $this->referer);     
       
         if ($this->interface)
           curl_setopt($this->ch, CURLOPT_INTERFACE, $this->interface);
       
         if ($this->httpget)
           curl_setopt($this->ch, CURLOPT_HTTPGET, $this->httpget);
       
         if ($this->writeheader != '')
           curl_setopt($this->ch, CURLOPT_WRITEHEADER, $this->writeheader);
    
         if ($this->postparams) {   
           curl_setopt($this->ch, CURLOPT_POST, 1);
           curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->postparams);
         }   
       
         if ($this->proxy)
           curl_setopt($this->ch, CURLOPT_PROXY, $this->proxy);
       
         if ($this->proxy_user_data)
           curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $this->proxy_user_data);
    
         if ($this->cookie)
           curl_setopt($this->ch, CURLOPT_COOKIE, $this->join_cookie());
       
         if (count($this->httpheader))
           curl_setopt($this->ch, CURLOPT_HTTPHEADER, $this->httpheader);
    
         if ($this->sslcert)
           curl_setopt($this->ch, CURLOPT_SSLCERT, $this->sslcert);
         
         if ($this->sslkey)
           curl_setopt($this->ch, CURLOPT_SSLKEY, $this->sslkey);
         
         if ($this->cainfo)
           curl_setopt($this->ch, CURLOPT_CAINFO, $this->cainfo);
       
         if ($this->cookiefile) {   
           curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookiefile);
           curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookiefile);
         }   
       
         $response = curl_exec($this->ch);
         $this->set_head(substr($response, 0, curl_getinfo($this->ch, CURLINFO_HEADER_SIZE)));
         $response = substr($response, curl_getinfo($this->ch, CURLINFO_HEADER_SIZE));
         $this->set_cookie();
       
         $this->postparams = array ();
       
         return $response;
       }
     
       function __destruct (){
         curl_close($this->ch);
       }
    }
    ?>
    
    хочу сделать авторизацию на один сайт,но сами параметры не передаются,авторизация через multipart/form-data

    при коде

    Code:
    <?php
    require_once 'curl.class.php';
    $curl = new curl ();
    $send=$curl->get('https://letyshops.ru/user');
    $pos = strpos($send,'logout');
    if ($pos === false) {
    $postdata=array('mail'=>'login','pass'=>'password','op'=>'');
    $send=$curl->post('https://letyshops.ru/ajax/login2/ajax',$postdata);
    echo 'не найдено';
    print_r($send);
    } else {
       echo 'найдено';
    }
    
    
    передаётся только

    Code:
    POST /ajax/login2/ajax HTTP/1.1
    User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20100101 Firefox/23.0
    Host: letyshops.ru
    Accept-Encoding: gzip,deflate
    Cookie: uid=0; old_session=MZVsUw5k9nkxKB6gKSKi-Mm8ZyM5TX2z1KeAtFLIGbA; bui=0; SSESS5288efca5cc8ebc9d12b8cd700a1566b=MZVsUw5k9nkxKB6gKSKi-Mm8ZyM5TX2z1KeAtFLIGbA
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
    Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7
    Content-Length: 344
    Expect: 100-continue
    Content-Type: multipart/form-data; boundary=----------------------------209c8d3994a2
    
    
    
    
    весь вечер бьюсь,с другими сайтами всё нормально
     
  2. blackbox

    blackbox Elder - Старейшина

    Joined:
    31 Dec 2011
    Messages:
    362
    Likes Received:
    62
    Reputations:
    11
    Прогнал через фидлер - все работает, ничего не менял в коде.
     
  3. Prog-t

    Prog-t New Member

    Joined:
    24 Nov 2015
    Messages:
    17
    Likes Received:
    2
    Reputations:
    0
    то есть и параметры передаются?

    [​IMG]
     
  4. blackbox

    blackbox Elder - Старейшина

    Joined:
    31 Dec 2011
    Messages:
    362
    Likes Received:
    62
    Reputations:
    11
    да
     
Loading...
Similar Threads - curl https передаются
  1. raarkil
    Replies:
    4
    Views:
    2,760