Skip to content

Commit 55dafa3

Browse files
committed
fix bug #86 PHP 5.6 SSL bug
According to http://sourceforge.net/p/phpcrawl/bugs/86/ fix PHP 5.6 SSL bug. But use "peer_name" depending on PHP version. So implemented a version check to st right SSL value.
1 parent 6902388 commit 55dafa3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

libs/PHPCrawlerHTTPRequest.class.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ protected function openSocket(&$error_code, &$error_string)
533533
// Get IP for hostname
534534
$ip_address = $this->DNSCache->getIP($this->url_parts["host"]);
535535

536+
// since PHP 5.6 SNI_server_name is deprecated
537+
if (version_compare(PHP_VERSION, '5.6.0') >= 0) {
538+
$serverName = 'peer_name';
539+
} else {
540+
$serverName = 'SNI_server_name';
541+
}
542+
536543
// Open socket
537544
if ($this->proxy != null)
538545
{
@@ -544,7 +551,11 @@ protected function openSocket(&$error_code, &$error_string)
544551
// If ssl -> perform Server name indication
545552
if ($this->url_parts["protocol"] == "https://")
546553
{
547-
$context = stream_context_create(array('ssl' => array('SNI_server_name' => $this->url_parts["host"])));
554+
$context = stream_context_create(array(
555+
'ssl' => array(
556+
$serverName => $this->url_parts["host"],
557+
),
558+
));
548559
$this->socket = @stream_socket_client($protocol_prefix.$ip_address.":".$this->url_parts["port"], $error_code, $error_str,
549560
$this->socketConnectTimeout, STREAM_CLIENT_CONNECT, $context);
550561
}
@@ -911,7 +922,8 @@ protected function buildRequestHeader()
911922

912923
$headerlines[] = "Host: ".$this->url_parts["host"]."\r\n";
913924

914-
$headerlines[] = "User-Agent: ".str_replace("\n", "", $this->userAgentString)."\r\n"; $headerlines[] = "Accept: */*\r\n";
925+
$headerlines[] = "User-Agent: ".str_replace("\n", "", $this->userAgentString)."\r\n";
926+
$headerlines[] = "Accept: */*\r\n";
915927

916928
// Request GZIP-content
917929
if ($this->request_gzip_content == true)
@@ -968,9 +980,9 @@ protected function buildRequestHeader()
968980
* Prepares the given HTTP-query-string for the HTTP-request.
969981
*
970982
* HTTP-query-strings always should be utf8-encoded and urlencoded afterwards.
971-
* So "/path/file?test=tatütata" will be converted to "/path/file?test=tat%C3%BCtata":
983+
* So "/path/file?test=tat�tata" will be converted to "/path/file?test=tat%C3%BCtata":
972984
*
973-
* @param stirng The quetry-string (like "/path/file?test=tatütata")
985+
* @param stirng The quetry-string (like "/path/file?test=tat�tata")
974986
* @return string
975987
*/
976988
protected function prepareHTTPRequestQuery($query)

0 commit comments

Comments
 (0)