简体   繁体   English

get_file_content不适用于https

[英]get_file_content not working for https

I am using php and google's new CSE in my website . 我在我的网站上使用php和google的新CSE The URL for request is like https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=017576662512468239146:omuauf_lfve&q=lectures 请求的网址类似于https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=017576662512468239146:omuauf_lfve&q=lectures

The connection is https and file_get_content() is getting failed. 连接是https,file_get_content()失败。 How can i get it working? 我该如何运作?
Since i need to host the site on some external web-hosting servers, I am in need of solution which don't alter php configuration file or work with default options found on most of web-hosting sites. 由于我需要在一些外部网络托管服务器上托管网站,我需要的解决方案不会改变php配置文件或使用大多数网站托管网站上的默认选项。

You can use curl : 你可以使用curl

## HTTPS url that you are targeting.
$url = "https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=017576662512468239146:omuauf_lfve&q=lectures";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.23 (Windows NT 5.1; U; en)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

## Below two option will enable the HTTPS option.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
$result = curl_exec($ch);
echo $result;

If you can't modify the config yourself, talk to the hosting provider. 如果您无法自行修改配置,请与托管服务提供商联系。 It most probably has to do with the lacking of openssl in the php core or startup. 这很可能与php核心或启动程序中缺少openssl有关。

If you are doing this for someone else and you have no control or contact with the host (the "some external host"), explain the situation and help them find a suitable host with the appropriate features enabled. 如果您正在为其他人执行此操作,并且您无法控制或与主机(“某些外部主机”)建立联系,请说明情况并帮助他们找到启用了适当功能的适当主机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM