Why I’m getting 500 error when using file_get_contents(), but works in a browser?

Try this workaround:

$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('https://www.example.com',false,$context);

If this doesn’t work, maybe you cant read from https?

Leave a Comment