SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get_file_contents($url) and traffic logs

    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?

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Um. I have some trouble understanding the jargon-laden explanations on php.net. Could you please explain?

  4. #4
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by geiger View Post
    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.

  5. #5
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Referrer header isn't sent at all. If you want more control over what is sent use cURL.

  7. #7
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    decowski, Does that mean there will be zero information about where the file read is coming from using get_file_contents?

  8. #8
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by geiger View Post
    decowski, Does that mean there will be zero information about where the file read is coming from using get_file_contents?
    There will be IP and, perhaps, hostname of your server.

  9. #9
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    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); 
    Salathe
    Software Developer and PHP Manual Author.

  10. #10
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome. Thanks, everyone.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •