If get_file_contents is used to read a URL, how does that show up to traffic logs (since the script is not a browser, doesn't have browser properties, etc.). Is there a way to toggle whether or not it shows at all?
| SitePoint Sponsor |
If get_file_contents is used to read a URL, how does that show up to traffic logs (since the script is not a browser, doesn't have browser properties, etc.). Is there a way to toggle whether or not it shows at all?




http://uk2.php.net/manual/en/wrappers.http.php
Off Topic:
Post count (386): My first PC nearly 20 years ago. It was a 386 25MHz. That's 0.025 GHz. Oh, and it had 2MB RAM and 40MB harddrive
Pawel Decowski (you should follow me on Twitter)
Um. I have some trouble understanding the jargon-laden explanations on php.net. Could you please explain?




A request made by file_get_contents is a regular GET request. It will show in the target server's logs as a request from the server your script is hosted on. You may explicitly state user agent, as in the document I linked to. If you don't then no user agent header is sent.
Pawel Decowski (you should follow me on Twitter)
Thanks. Does the "referrer" show as the URL of the script? If so, is it possible to change the URL displayed as the referrer to a different directory?




Referrer header isn't sent at all. If you want more control over what is sent use cURL.
Pawel Decowski (you should follow me on Twitter)
decowski, Does that mean there will be zero information about where the file read is coming from using get_file_contents?




Pawel Decowski (you should follow me on Twitter)
If you want to customise the request, you can create and use a stream context (stream_context_create).
PHP Code:$ctx = stream_context_create(array('http' => array(
'header' => implode("\r\n", array(
'User-Agent: Salathe 1.0 (http://www.sitepoint.com/forums/showthread.php?t=597424)',
'Referer: http://www.sitepoint.com/forums/showthread.php?t=597424'
))
)));
$content = file_get_contents('http://example.org/', FALSE, $ctx);
Awesome. Thanks, everyone.
Bookmarks