As the title says, why won’t this code work?
$homepage = file_get_contents('https://www.google.com');
echo $homepage;
$file = 'code.txt';
file_put_contents($file, $homepage);
Gives me the error
"PHP Warning: file_get_contents(https://www.google.com): Failed to open stream: No such file or directory in C:UsersStevepublic_htmlindex.php on line 11"
Thank you for your time
I tried the above code and have tried other solutions, my allow_fopen is set to on
2
Answers
The website uses methods to stop it being scraped, it required the Cookie in the Header
Try using file_get_contents with an http:// URL. If it works, it suggests that the problem may be related to your SSL/TLS settings.
Try opening the URL with curl in PHP. If curl can access the URL but file_get_contents cannot, it would suggest that the problem might be with PHP’s stream settings.