Jump to content

Fetching the File content, via file_get_contents


abhi_madhani

Recommended Posts

Hi,

 

I am trying to fetch a file with function file_get_contents() from a website, but am getting following error.

 

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /data/22/1/27/17/1842180/user/1999295/htdocs/web/modules/index.php on line 14.

 

using following code,

 

	$content = file_get_contents($source);

$handle = fopen($destination, 'wb');
fwrite($handle, $content);
fclose($handle);

 

does it have something to with http header, which might be required to set as HTTP/1.1 in php

 

Regards,

Abhishek

Link to comment
Share on other sites

http://www.checkupdown.com/status/E403.html

 

There are any number of reasons you could be getting that error but the short answer is that for whatever reason, the server is denying access to that page.  It is possible that the server has script to detect that it is another server making the request (instead of a browser).  You may have to get around it by faking any number of things, from headers to cookies to...anyways, you'd have to fake it by getting by setting stuff and getting contents with cURL instead of file_get_contents().  Or the URL could just be forbidden because that's how the directory/file permission is set.  Have you tried to go to the URL in $source in your browser?

Link to comment
Share on other sites

Hi,

 

The url can be accessed in normal browser,

 

Your suggestion is possible that the source server has script in place, which only allows browsers to make the request, and not any to any other type of applications or scripts.

 

My website url might not be blocked, but it could be my hosts server's ip address that is blocked.

 

I will try to implement curl() to accomplish this task, and will see how can the identity be faked as a real browser. Thanks for your suggestion, will post here back if any of the solutions works.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.