How to access main domain folder using file_get_contents from subdomain

I am trying to access a main domain folder using file_get_contents from a subdomain, and when I do, it says on google console that it’s trying to request cors headers from infinityfree error 404 (meaning the file isn’t found). I’m pretty sure that I am accessing the path right, but could someone check? I can’t include the whole web address as I use htaccess to block the contents of it otherwise. I tried unblocking it for only that subdomain with htaccess, but it gave me an error and didn’t work (I don’t know what the error was either, it just said check your htaccess, and I can’t find content online). I don’t know if you are able to access main access folders from a subdomain using file_get_contents. If that is the case, can someone tell me how, or if it’s not possible? Thanks in advance. My code is: $updates = file_get_contents('../../../'); // from htdocs

If your using file_get_contents just put your whole site URL. So in your case, the URL would be

Or in code:

$updates = file_get_contents("");
1 Like

Forgot to say I use htaccess to block that page, so I need to use a relative url. I’ll add that for people who need that info. Thanks for trying to help :confused:

Its not possible then. Access via the root is blocked.

Really? Oh, great :roll_eyes:. Well, thanks anyways. I hope that I can find a work-around then. Thanks for the help.

I’m sorry, but I don’t see an easy workaround for this.

file_get_contents can be used to retrieve both local files and website URLs. But using this to retrieve files from other sites on the same account can’t be done because:

  • Every PHP script can only access the files in their own website directory. For security, scripts in one domain on your account cannot access files on another domain.
  • We have a security system which means that only web browsers can be used to access websites we host, which means using file_get_contents running anywhere to a website hosted here will be blocked.

Thanks anyway. I have another hosting/coding site that allows you to host codes called I may just have to store whatever I am using in a local file on that subdomain.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.