Question:
Why is file_get_contents() working on one URL but not another?
HiFi
2011-10-20 08:30:40 UTC
I have two URLs (currently locally). For the sake of this example, they shall be:

local/site/user/me/
local/site/user/you/

The pages are user profiles. The pages a) are called based on .htaccess from the system and b) when viewed normally, point to the right pages (read: they exist). I have a second set of pages with additional content that, due to the systems I am using, will not allow for PHP data from one system to pass untouched onto the other. I am using echo file_get_contents($profileurl); to insert the HTML code into my outer profile page. Regardless of who I am logged in as or if I am logged in at all, I can view the profile for user "me" but not user "you". It tells me that there is a 404 page and the profile page for user "you" can not be found.

The page exists as I am currently viewing the page. I have also used the $profileurl string as a HREF value and it links to the correct page. What, if anything, can be done to fix this? Is it a localhost issue or a page issue?
Three answers:
just "JR"
2011-10-20 08:48:16 UTC
Extract of your htaccess is needed. However, selecting a page should NOT be done through htaccess!

Extracts of your profile pages is needed, or their names.

You should not be using:

$profileurl = "local/site/user/me/";

This points to "local/site/user/me/index.xxx", unless changed by your htaccess.

file_get_contents should use a full path filename, ie "local/site/user/me/profile.html" or "local/site/user/me/profile.php" or whatever.

Your problem, I believe, is in your htaccess... as MANY people use it the wrong way...

(Unless you are VERY experienced, DON'T EVER touch htaccess: some unix systems may even change/reset it without your knowledge...)
i8badhaggis
2011-10-20 08:49:01 UTC
You need to realize that file_get_contents is a server grabbing a page from another server. It does not have any of the cookies that you do when viewing the page i.e. being logged in therefore the page will come off being different than were you yourself to open it in a browser. As to why it can't seem to find the page at all, it could be because the path you have listed is a relative path. the method may be trying to find the file relative to the file containing the file_get_contents. try using a full path when calling and see if that helps.
?
2016-10-21 13:53:43 UTC
i'm assuming that the two web content are on distinctive servers and not hosted with the aid of an analogous corporation (in the event that they have been, there could probable be an less demanding and speedier thank you to try this - like scp): See ch 39 of the Hypertext Preprocessor documentation: distant records


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...