Reputation: 15664
I am receiving an error message in PHP 5 when I try to open a file of a different website. So the line
fopen("http://www.domain.com/somefile.php", r)
returns an error
Warning: fopen(www.domain.com/somefile.php) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in D:\xampp\htdocs\destroyfiles\index.php on line 2
Upvotes: 2
Views: 10487
Reputation: 114
I had a similar issue, access with curl works fine. But with php and fopen, I got an http 403
192.168.1.144 - "GET /dop007.pdf HTTP/1.0" 403 392 "-" "-"
192.168.1.144 - "GET /dop007.pdf HTTP/1.1" 302 430 "-" "curl/7.58.0"
I could fix the issue with changing the HTTP Version to 1.1
$context = stream_context_create([
'http'=>[
'protocol_version' => 1.1
]
]);
if ($file = fopen($filePath, 'rb',false,$context)) {
while ( ! feof($file) and (connection_status() == 0)) {
print(fread($file, 1024 * 8));
flush();
}
fclose($file);
} else {
Log::error('Search Request Failed');
}
Upvotes: 0
Reputation: 17555
Your PHP app failed to authenticate. The request URI should be:
http://user:[email protected]/somefile.php
Upvotes: 1
Reputation: 122769
It looks like your PHP client (i.e. the server on which your PHP script is running) isn't allowed to get http://www.domain.com/somefile.php
, by the server on www.domain.com
.
Upvotes: 0