LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   fopen() in PHP (https://www.linuxquestions.org/questions/programming-9/fopen-in-php-878056/)

wh33t 04-30-2011 06:20 PM

fopen() in PHP
 
Hey LQ,

Just a quick question. If I were to use PHP to read an RSS page that is online, what "browser" (user-agent) would the webserver detect my PHPs request as? If that doesn't make any sense I'm referring to information such as

Code:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17 ( .NET CLR 3.5.30729)

paulsm4 04-30-2011 07:55 PM

Good question.

It depends, at least in part, on HOW you're using PHP to read the URL.

Here's an example snippet, that uses PHP's built-in "DOMDocument" class:

http://www.softarea51.com/tutorials/..._php.html#code
Code:

<?php

  $doc = new DOMDocument();
  $doc->load('http://www.softarea51.com/rss/windows/Web_Development/XML_CSS_Utilities.xml');
  $arrFeeds = array();
  foreach ($doc->getElementsByTagName('item') as $node) {
    $itemRSS = array (
      'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
      'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
      'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
      'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
      );
    array_push($arrFeeds, $itemRSS);
  }

?>

I believe in this example, the server (www.software51.com) wouldn't see ANY user agent ... because I don't believe DOMDocument->load() writes one in its httpd header.

You can easily verify this by using the above code to access a sample xml document on your own web server, and see what the web server reports (e.g. look at your access_log).

Guttorm 05-01-2011 09:48 AM

Hi

From php.ini:

Quote:

; Define the User-Agent string. PHP's default setting for this is empty.
; http://php.net/user-agent
;user_agent="PHP"


All times are GMT -5. The time now is 02:54 PM.