【问题标题】:load https website with php用 php 加载 https 网站
【发布时间】:2012-03-28 17:55:51
【问题描述】:

您好,我有以下问题,

我想用 php 建立一个网站。我使用了 CURL,但在我的服务器上我设置了 open_basedir。

所以,我收到以下错误消息:

CURLOPT_FOLLOWLOCATION 在安全模式下或设置了 open_basedir 时无法激活

代码是:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$store = curl_exec ($ch);
$error = curl_error ($ch);
return $store;

有没有其他方法可以使用 php 加载网站?!

谢谢

【问题讨论】:

  • 您可能根本不需要CURLOPT_FOLLOWLOCATION。只需删除该行。
  • 你仍然可以使用 curl,你只需要手动进行重定向。
  • @Brian:仅当特定 url 重定向到实际内容时。不是每个人都使用重定向...

标签: php curl https


【解决方案1】:

您可以尝试使用file_get_contents()获取网站内容:

 $content = file_get_contents('http://www.example.com/');

 // to specify http headers like `User-Agent`,
 // you could create a context like so:
 $options = array(
   'http' => array(
      'method' => "GET",
      'header' => "User-Agent: PHP\r\n"
   )
 );
 // create context
 $context = stream_context_create($options);
 // open file with the above http headers
 $content = file_get_contents('http://www.example.com/', false, $context);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-01-17
  • 1970-01-01
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
  • 2017-11-24
  • 2017-04-30
  • 1970-01-01
相关资源
最近更新 更多