dsfdsfsdf45489
2013-09-13 15:07
浏览 51
已采纳

使用curl登录到https网站不工作,怀疑godaddy验证与它有关

I use the following general code to log into other https sites and pull records using forms, but it doesn't seem to work for www.voip.ms. I've created a testing account so if anyone wants to take a crack at it and tell me what I did wrong. (Warning, the site only gives your IP address 4 tries until it bans it)

<?php
ini_set('max_execution_time', 300);
$username="meahmatt@aol.com"; 
$password="testaccount"; 
$url="https://www.voip.ms/m/login.php"; 
$cookie="cookie.txt"; 

$postdata = "col_email".$username."&col_password=".$password."&action=login&form1="; 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 
curl_close($ch);
echo $result;
?>

I've also tried setting CURLOPT_SSL_VERIFYPEER, TRUE with no change

图片转代码服务由CSDN问答提供 功能建议

我使用以下通用代码登录其他https网站并使用表单提取记录,但似乎没有 为www.voip.ms工作。 我已经创建了一个测试帐户,所以如果有人想破解它并告诉我我做错了什么。 (警告,网站只给你的IP地址4次尝试,直到它禁止它)

 &lt;?php 
ini_set('max_execution_time',300); 
 $ username =  “meahmatt@aol.com”;  
 $的密码= “testaccount”;  
 $的URL = “https://www.voip.ms/m/login.php”;  
 $的饼干= “cookie.txt”;  
 
 $ postdata =“col_email”。$ username。“&amp; col_password =”。$ password。“&amp; action = login&amp; form1 =”;  
 
 $ ch = curl_init();  
curl_setopt($ ch,CURLOPT_URL,$ url);  
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,FALSE);  
curl_setopt($ ch,CURLOPT_USERAGENT,“Mozilla / 5.0(Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6)Gecko / 20070725 Firefox / 2.0.0.6”);  
curl_setopt($ ch,CURLOPT_TIMEOUT,60);  
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,1);  
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);  
curl_setopt($ ch,CURLOPT_COOKIEJAR,$ cookie);  
curl_setopt($ ch,CURLOPT_COOKIEFILE,$ cookie);  
curl_setopt($ ch,CURLOPT_REFERER,$ url);  
 
 ncurl_setopt($ ch,CURLOPT_POSTFIELDS,$ postdata);  
curl_setopt($ ch,CURLOPT_POST,1);  
 $ result = curl_exec($ ch);  
curl_close($ ch); 
echo $ result; 
?&gt; 
   
 
 

我也尝试过设置CURLOPT_SSL_VERIFYPEER,TRUE没有变化

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douluo5937 2014-01-09 09:04
    已采纳

    I had the same problem recently trying to use the twitter api using curl_exec from godaddy.

    The magic was to disable both peer and host verification in the options :

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // required as godaddy fails
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // required as godaddy fails
    

    The error was a certificate verification problem. I have no problem using this exact script on non-godaddy servers.

    CURLE_SSL_CACERT (60)
    Peer certificate cannot be authenticated with known CA certificates.
    

    The full request looks like this :

      $url = "https://api.twitter.com/1.1/statuses/user_timeline.json?..."
        $headers = array( 
            "Authorization: Bearer ".$bearer."",
        ); 
    
    $ch = curl_init();  // setup a curl
    curl_setopt($ch, CURLOPT_URL, $url);  // set url to send to
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set custom headers
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return data reather than echo
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // required as godaddy fails
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // required as godaddy fails
    
    // $info = curl_getinfo($ch); // debug info
    // var_dump($info); // dump curl info
    
    $result = curl_exec($ch); // run the curl
    
    curl_close($ch);  // stop curling
    
    // Check for errors and display the error message
    if($errno = curl_errno($ch)) { echo "curlerror::$errno::"; }
    

    Also notice that curl_getinfo and curl_errno were invaluable at finding the problem.

    tl;dr , friends don't let friends use godaddy.

    点赞 评论
  • dsaj20411 2013-09-13 15:15

    You could try this function if you like. It's helped me out a few times. If you still have trouble try fiddler2 (fiddler2.com) to check for all of the headers and attempt to replicate them in PHP

    ini_set('max_execution_time', 300);
    $fields['col_email'] = "meahmatt@aol.com"; 
    $fields['col_password'] = "testaccount"; 
    $fields['action'] = "login"; 
    $fields['form1'] = ""; 
    $url = "https://www.voip.ms/m/login.php"; 
    $html = get_html($url,$url,$fields);
    
    function get_html($url,$ref='',$fields=array(),$cookie='cookie.txt'){
    //  $proxyAddress = '127.0.0.1:8888';
        $ch = curl_init();
        touch($cookie);
        $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
        $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
        $header[] = "Cache-Control: max-age=0";
        $header[] = "Connection: keep-alive";
        $header[] = "Keep-Alive: 300";
        $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
        $header[] = "Accept-Language: en-us,en;q=0.5";
        $header[] = "Pragma: "; //browsers keep this blank.  
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows;U;Windows NT 5.0;en-US;rv:1.4) Gecko/20030624 Netscape/7.1 (ax)');
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        if($proxyAddress != ''){
            curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
            curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
            curl_setopt($ch, CURLOPT_PROXY, $proxyAddress);
        }
        if(count($fields)>0){
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
            curl_setopt ($ch, CURLOPT_POST, 1); 
        }
        curl_setopt($ch, CURLOPT_REFERER, $ref);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
        $result = curl_exec ($ch);
        if(!$result){
            echo "cURL error number:" .curl_errno($ch);
            echo "cURL error:" . curl_error($ch);
            exit;
        }
        curl_close ($ch);
        return($result);
    }
    
    点赞 评论

相关推荐 更多相似问题