2

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/somef­ile.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

3 Answers 3

1

Your PHP app failed to authenticate. The request URI should be:

http://user:[email protected]/somefile.php
Sign up to request clarification or add additional context in comments.

Comments

0

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/somef­ile.php, by the server on www.domain.com.

1 Comment

Either that or his local network is on a proxy and PHP isn't authorizing.
0

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');
}                

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.