这是我的代码
$url = 'http://www.wikipedia.com'; // URL WITH HTTP
$hurl = str_replace("http", "https", $url); // URL WITH HTTPS
$urlheads = get_headers($url, 1);
$surlheads = get_headers($hurl, 1);
$urlx = false;
$surlx = false;
foreach ($urlheads as $name => $value)
{
if ($name === 'Location')
{
$urlx=$value;
}
else{
}
}
print_r($urlx);
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
Warning: get_headers(): Peer certificate CN=`*.wikipedia.org' did not match expected CN=`www.wikipedia.com' in....
Warning: get_headers(): Failed to enable crypto in....
Warning: get_headers(https://www.wikipedia.com): failed to open stream: operation failed in .....
Array ( …Run Code Online (Sandbox Code Playgroud)