2017-04-20 135 views
1

我正在運行PHP版本5.5.12作爲WAMP的一部分。PHP CURL WAMP - SSL證書錯誤:無法獲取本地發行者證書

當我嘗試執行此代碼,我發現了以下錯誤: SSL證書錯誤:無法獲取本地頒發者證書 這個腳本的目的是得到認證的形式通過用戶名和密碼的內容。

<?php 

include('simple_html_dom.php'); 
ini_set('max_execution_time', 0); 
error_reporting(E_ALL); 
ini_set('display_errors', 1); 
ini_set('memory_limit', '2G'); 

class EmailScraping { 

    public $url; 

    public function __construct($url) { 
     if ($this->validUrl($url)) 
      $this->url = $url; 
     else { 
      echo 'bad url <br>'; 
     } 
    } 

    public function getContent() { 

     $username = "****"; 
     $password = "****"; 

     //login form action url 
     $url = 'https://placement.emploiquebec.gouv.qc.ca/mbe/login/portail/auth.asp?provenance=emplr&CL=french'; 
     $postinfo = "posted&L_OBLG_NOM_UTIL=Votre code d'utilisation&OBLG_NOM_UTIL=" . $username . "&L_OBLG_MOT_PASSE=Votre mot de passe&OBLG_MOT_PASSE=" . $password . "&continuer=CONTINUER&LastLogin&NbEssai=0"; 

     $cookie_file_path = "./cookies.txt"; 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_NOBODY, false); 
     curl_setopt($ch, CURLOPT_HEADER, false); 
     curl_setopt($ch, CURLOPT_ENCODING , ""); 
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
     //set the cookie the site has for certain features, this is optional 
     curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0"); 
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7"); 
     curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);   
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  
     curl_setopt($ch, CURLOPT_CAINFO, getcwd() . '\cacert.pem'); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);  
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_MAXREDIRS, 10); 
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo); 
     $html1 = curl_exec($ch); 
     curl_close($ch); 

     $ch = curl_init(); 

     //page with the content I want to grab 
     curl_setopt($ch, CURLOPT_URL, "https://placement.emploiquebec.gouv.qc.ca/mbe/ut/suivroffrs/esuivroffrs.asp?CL=french"); 
     curl_setopt($ch, CURLOPT_POST, false); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, ""); 
     $answer = curl_exec($ch); 

     if (curl_error($ch)) { 
      echo curl_error($ch); 
     } 

     curl_close($ch); 
     return $answer; 
    } 

    public function validUrl($url) { 

     if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)) { 
      return false; 
     } 
     return true; 
    } 

} 

$scraper = new EmailScraping('https://www.facebook.com'); 
$result = $scraper->getContent(); 
$html = "<base href='https://placement.emploiquebec.gouv.qc.ca/mbe/login/portail/auth.asp?provenance=emplr&CL=french' />" . $result; 
echo $html; 

我試圖在php.ini文件中添加此代碼並重新啓動WAMP服務器,但仍然收到相同的錯誤。

curl.cainfo="C:/wamp/www/domscraper/cacert.pem" 

我真的不知道還有什麼可以嘗試的。

任何人都可以建議我還有什麼可以嘗試?

+0

是'curl.cainfo =「C:/wamp/www/domscraper/cacert.pem」'正確的路徑/文件存在嗎? –

+0

是這個路徑/文件存在@Antonis Tsimourtos –

+0

也許嘗試下載和替換[this](https://curl.haxx.se/ca/cacert.pem) –

回答

3

你有curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

嘗試將其設置爲false

下面是一些文檔的鏈接 - http://php.net/manual/en/function.curl-setopt.php

這應該是唯一的發展,在督促你應該解決所有證書問題,可能會需要從提供商處獲得證書/密鑰。

有關錯誤日誌添加(並檢查了額外信息的文檔)

$verbose = fopen ('php://temp', 'w+'); 
curl_setopt ($curlManager, CURLOPT_VERBOSE, true); 
curl_setopt ($curlManager, CURLOPT_STDERR, $verbose); 

您也可以嘗試,如果沒有必要的調試消除其中的一些選項。

+0

我試着用curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,假),但仍然得到同樣的錯誤。我只是喜歡從登錄表單傳遞用戶名和密碼的內容。請任何幫助。 –

+0

編輯答案以包含錯誤日誌記錄,而不是將其放入註釋中。 – DaveCoast

0

這是韌皮配置:從 curl_setopt變化($ CH,CURLOPT_SSL_VERIFYPEER,TRUE); 至 curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);

我一直在試圖連接到由郵差做的API,它的工作原理。

我在Windows 64位上使用WAMP(PHP7 + Apache)。

相關問題