Forum Moderators: coopster

Message Too Old, No Replies

Warning: file_get_contents

Warning: file_get_contents

         

aff_dan

3:51 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



Hello!

I have a problem with a PHP page named search.php, this file will get content from another Web site page.

I get this error:

Warning: file_get_contents(http://apps5.site.com/apps/domainarticle/article.cgi?cid=M45&&hl=en&ac=p&q=Design): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/bestlo/public_html/my-mesm/search.php on line 9

How to fix this error? Any help please

Regards,
Dan

bcolflesh

3:54 pm on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



403 Forbidden means that the server is denying your request - they may have blocked your IP or User Agent - try sending a generic UA with the request, if you aren't sending anything at all.

aff_dan

4:00 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



What is "generic UA with the request"?

Dan

bcolflesh

4:02 pm on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the ini_set command to add a generic User Agent, ex:

ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)');

aff_dan

4:17 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



My script begins with:

<?

66.102.9.147
$qq=str_replace(" ","%20", $q);
$filename = "http://apps5.site.com/apps/domainarticle/article.cgi?cid=45&hl=en&ac=p&q=".$qq."";
$data = file_get_contents($filename);

how to add that browser info?

coopster

12:08 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ini_set() [php.net] sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

You don't have to add it to your query string at all. By the way, PHP has a nice little function that does your str_replace and more. See urlencode() [php.net] for more information.