PHP Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead in
這裡就是把
curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, true );
改成
curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, 2 );
就可以了嗎?
回複內容:
PHP Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead in
這裡就是把
curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, true );
改成
curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, 2 );
就可以了嗎?
是的
CURLOPT_SSL_VERIFYHOST的值
- 設為
0表示不檢查認證
- 設為
1表示檢查認證中是否有CN(common name)欄位
- 設為
2表示在1的基礎上校正當前的網域名稱是否與CN匹配
而libcurl早期版本中這個變數是boolean值,為true時作用同目前設定為2,後來出於調試需求,增加了僅校正是否有CN欄位的選項,因此兩個值true/false就不夠用了,升級為0/1/2三個值。
再後來(libcurl_7.28.1之後的版本),這個調試選項由於經常被開發人員用錯,被去掉了,因此目前也不支援1了,只有0/2兩種取值。
引自 libcurl API
When the verify value is 1, curl_easy_setopt will return an error and
the option value will not be changed. It was previously (in 7.28.0 and
earlier) a debug option of some sorts, but it is no longer supported
due to frequently leading to programmer mistakes. Future versions will
stop returning an error for 1 and just treat 1 and 2 the same.
最新版本,它的預設值就是2,因此,這行代碼,可以省略不寫。