Reputation: 1462
My site went down recently and the hosting company helped recover it. After that i keep getting this error on one of my pages.
[22-Oct-2017 02:54:03 UTC] PHP Fatal error: Cannot redeclare get_headers() in C:\inetpub\vhosts\mysite.com\httpdocs\html\blue\inc\ip_redirect.php on line 92
Here is the method that the code is referring to. I did check and this is whats causing the HTTP 500 errors.
function get_headers($url,$format=0)
{
$url=parse_url($url);
$end = "\r\n\r\n";
$fp = fsockopen($url['host'], (empty($url['port'])?80:$url['port']), $errno, $errstr, 30);
if ($fp)
{
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: ".$url['host']."\r\n";
$out .= "Connection: Close\r\n\r\n";
$var = '';
fwrite($fp, $out);
stream_set_timeout($fp, 5);
while (!feof($fp))
{
$var.=fgets($fp, 1280);
$info = stream_get_meta_data($fp);
if ($info['timed_out']) {
echo 'Connection timed out!';
return "";
}
if(strpos($var,$end))
break;
}
fclose($fp);
$var=preg_replace("/\r\n\r\n.*\$/",'',$var);
$var=explode("\r\n",$var);
if($format)
{
foreach($var as $i)
{
if(preg_match('/^([a-zA-Z -]+): +(.*)$/',$i,$parts))
$v[$parts[1]]=$parts[2];
}
return $v;
}
else
return $var;
}
}
Upvotes: 0
Views: 579
Reputation: 2597
The method get_headers
is an internal function from PHP.
http://php.net/manual/en/function.get-headers.php
The method looks like some sort of polyfill. You have to either remove this method, or wrap it in a function_exists
statement.
If none are options, than you might want to reach out to this scary method. Haven't used it myself. http://php.net/manual/en/function.runkit-function-remove.php
Upvotes: 1