search

Home  >  Q&A  >  body text

php - curl参数设置的问题 有关CURLOPT_SSL_VERIFYHOST

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 );

就可以了吗?

天蓬老师天蓬老师2901 days ago444

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-10 15:11:47

    是的

    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,因此,这行代码,可以省略不写。

    reply
    0
  • Cancelreply