Answer the question
In order to leave comments, you need to log in
Why won't PHP connect over ssl via fsockopen?
$f = get('https://twitter.com/', 'https://twitter.com/', $_SERVER['HTTP_USER_AGENT'], '', true);
var_dump($f);
function get($url, $ref, $ua, $cook, $ssl)
{
$url = parse_url($url);
$line="";
$connecthost = $ssl ? 'ssl://' . $url['host'] : $url['host'];
$port = $ssl ? 443 : 80;
$fp=fsockopen($connecthost, $port, $errno, $errstr, 60);
if(!$fp) {
return $connecthost . ': ' . $errstr;
}
else
{
$query = isset($url['query']) ? '?' . $url['query'] : '';
$path = $url['path'] . $query;
$headers = "GET $path HTTP/1.1\r\n";
$headers .="Host: {$url['host']}\r\n";
$headers .="User-Agent: $ua\r\n";
$headers .= "Accept-Language: en,en-US;q=0.9,en;q=0.8\r\n";
$headers .="Cookie: $cook\r\n";
$headers .="Connection: Close\r\n";
$headers .="Referer: $ref\r\n\r\n";
fwrite($fp, $headers);
while(!feof($fp)){
$line .= fgets($fp, 1024);
}
fclose($fp);
}
return $line;
}
Answer the question
In order to leave comments, you need to log in
Perhaps the problem is that the allow_url_fopen parameter in php.ini is disabled.
It may also be that the SSL module is not enabled, look in phpinfo()
$fp=fsockopen($connecthost, $port, $errno, $errstr, 60);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question