【php – 仅对登录页面使用https而不是整个网站】教程文章相关的互联网学习教程文章

phpcurl获取https请求的2种方法_PHP

今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed” 很明显,验证证书的时候出现了问题。 使用curl如果想发起的https请求正常的话有2种做法: 方法一、设定为不验证证书和host。 在执行curl_exec()之前。设置option代码如下: $ch = curl_init(); ...... curl_setopt(...

PHP简单实现HTTP和HTTPS跨域共享session解决办法_PHP

HTTP、HTTPS协议下session共享解决cookie失效 的办法:(也许不是最好的,但是实用) 原理就是把session id设置到本地的cookie,代码如下: $currentSessionID = session_id(); session_id($currentSessionID );简单事例代码: (HTTP)代码如下: session_start(); $currentSessionID = session_id(); $_SESSION[testvariable] = Session worked; $secureServerDomain = www.sjolzy.cn; $securePagePath = /safePages/secureP...

php使用curl打开https网站的方法_PHP

本文实例讲述了php使用curl打开https网站的方法。分享给大家供大家参考。具体实现方法如下:$url = https://www.google.com.hk; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537...

PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)_PHP

方法一: 在php中,抓取https的网站,提示如下的错误内容:Warning: file_get_contents() [function.file-get-contents]: failed to open stream: Invalid argument in I:Webmyphpa.php on line 16 打开php.ini文件找到 ;extension=php_openssl.dll ,去掉双引号”;” ,重启web服务器即可。 apache服务器的话,可以同时启用mod_ssl模块测试。如果不方便修改服务器配置,可以参考使用如下的函数来解决: 代码示例:<?php //file_get...

php抓取https的内容的代码_php技巧

直接用file_get_contents,会报错; 代码如下:$url = (https://xxx.com"); file_get_contents($url); 错误: Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.php on line 3 用curl的方式是可以的: 代码如下:$url = (https://xxx.com); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($...

如何使用php判断服务器是否是HTTPS连接_php技巧

代码如下:if ($_SERVER['HTTPS'] != "on") { echo "This is not HTTPS";}else{ echo "This is HTTPS";}if ($_SERVER['HTTPS'] != "on") { echo "This is not HTTPS";}else{ echo "This is HTTPS";}

解决file_get_contents无法请求https连接的方法_php技巧

错误: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? 解决方案有3: 1.windows下的PHP,只需要到php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了。 2.linux下的PHP,就必须安装openssl模块,安装好了以后就可以访问了。 3.如果服务器你不能修改配置的话,那么就使用curl函数来替代file_get_contents函数,当然不是简单的替...

php使用curl访问https示例分享_php实例

为方便说明,先上代码吧代码如下:/** * curl POST * * @param string url * @param array 数据 * @param int 请求超时时间 * @param bool HTTPS时是否进行严格认证 * @return string */ function curlPost($url, $data = array(), $timeout = 30, $CA = true){ $cacert = getcwd() . /cacert.pem; //CA根证书 $SSL = substr($url, 0, 8) == "https://" ? true : false; $ch = curl_i...

php之curl实现http与https请求的方法_php技巧

本文实例讲述了php之curl实现http与https请求的方法,分享给大家供大家参考。具体如下: 通常来说,php的curl函数组可以帮助我们把机器伪装成人的行为来抓取网站,下面来分享两个例子,一个是访问http网页,一个访问https网页,一起来看一下。 每次要使用curl的时候,总要查一堆资料。 现在将常用的几句保存下来,省的每次都去谷歌。常规curl请求:代码如下:$url = http://www.gxlcms.com; $curl = curl_init(); curl_setopt($curl...

PHP实现抓取HTTPS内容_php技巧【图】

最近在研究Hacker News API时遇到一个HTTPS问题。因为所有的Hacker News API都是通过加密的HTTPS协议访问的,跟普通的HTTP协议不同,当使用PHP里的函数 file_get_contents() 来获取API里提供的数据时,出现错误,使用的代码是这样的:<?php$data = file_get_contents("https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty");...... 当运行上面的代码是遇到下面的错误提示:PHP Warning: file_get_contents(): Un...

php中http与https跨域共享session的解决方法_php技巧

遇到了HTTP、HTTPS协议下session共享解决cookie失效的问题,这里提供一个临时解决办法。 实现原理:把session id设置到本地的cookie。 如下:代码如下: $currentSessionID = session_id(); session_id($currentSessionID );以下是实现代码,分为http与https两部分。 1,http部分:代码如下: <?php session_start(); $currentSessionID = session_id(); $_SESSION[testvariable] = Session worked; $secureServerDomain = www...

php使用curl获取https请求的方法_php技巧

本文实例讲述了php使用curl获取https请求的方法。分享给大家供大家参考。具体分析如下: 今日在做一个项目,需要curl获取第三方的API,对方的API是https方式的。 之前使用curl能获取http请求,但今天获取https请求时,出现了以下的错误提示:证书验证失败。 SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 解决方法为在...

phpcurl获取https请求的2种方法_php技巧

今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed” 很明显,验证证书的时候出现了问题。 使用curl如果想发起的https请求正常的话有2种做法: 方法一、设定为不验证证书和host。 在执行curl_exec()之前。设置option代码如下: $ch = curl_init(); ...... curl_setopt(...

php使用curl打开https网站的方法_php技巧

本文实例讲述了php使用curl打开https网站的方法。分享给大家供大家参考。具体实现方法如下: $url = https://www.google.com.hk; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, Mozilla/5.0 (Windows NT 6.1) AppleWebKit/53...

php抓取https的内容的代码

直接用file_get_contents,会报错; 代码如下:$url = (https://xxx.com"); file_get_contents($url); 错误: Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.php on line 3 用curl的方式是可以的: 代码如下:$url = (https://xxx.com); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($...