Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:03:47+00:00 2026-06-03T21:03:47+00:00

I am using php file_get_contents to get a webpage. When i am doing it

  • 0

I am using php file_get_contents to get a webpage.
When i am doing it from my localhost everything works good.
But as soon as i do it from my shared hosting i get this error message:

ERROR
Access Denied
Access Denied by security policy
The security policy for your network prevents your request from being allowed at this time. Please contact your administrator if you feel this is incorrect.

this is the header i get back

array(4) { [0]=> string(22) "HTTP/1.0 403 Forbidden" [1]=> string(23) 
"Content-Type: text/html" [2]=> string(17) "Connection: close" [3]=> string(19) 
"Content-Length: 353" }

the code is straightforward

$page = file_get_contents('http://www.somedomain.com/');

if i try for current page it works

 $page = file_get_contents('http://stackoverflow.com/questions/10565054/error-access-denied-when-using-php-file-get-content');

any ideas ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:03:48+00:00Added an answer on June 3, 2026 at 9:03 pm

    The remote webserver is rejecting your request. There’s no telling speficically why it is denying you. It could the server is configured to deny an IP range that includes wherever your shared hosting is. It could be that the server requires certain header information (like a host entry, or a certain user_agent, or something).Try setting some HTTP context stuff to appease the server you’re trying to contact. Here’s an example from the file_get_contents page.

    function file_get_contents_utf8($fn) { 
        $opts = array( 
            'http' => array( 
                'method'=>"GET", 
                'header'=>"Content-Type: text/html; charset=utf-8" 
            ) 
        ); 
    
        $context = stream_context_create($opts); 
        $result = @file_get_contents($fn,false,$context); 
        return $result; 
    }  
    

    If you can access the target from your browser, try duplicating allt he headers your browser is sending. Most browsers have some sort of plugin to show you exactly what headers are going out on the request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using php 5.2 and I am fetching data from url using file_get_contents
I'm using PHP's function file_get_contents() to fetch contents of a URL and then I
How to get the file names inside a directory using PHP? I couldn't find
using Fast CGI I can't get it to read the php.ini file. See my
I am downloading data from a php file using miniAjax. Here is what the
My jQuery code (using ajax) request's data from a local php script (pgiproxy.php). This
Using php coding, I'm attempting to make a script which will grab content from
I am using file_get_contents through proxy to fetch a webpage. This setup was working
Possible Duplicate: How to extract a node attribute from XML using PHP's DOM Parser
I'm using PHP's preg_match_all() to search a string imported using file_get_contents(). The regex returns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.