LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-30-2011, 06:20 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
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)
 
Old 04-30-2011, 07:55 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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).
 
Old 05-01-2011, 09:48 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SELINUX and php fopen.. How to? latino Linux - Server 1 02-11-2008 09:37 PM
FC3, PHP 4.3.9, and fopen PERMISSION DENIED Cottsay Programming 4 06-25-2005 02:39 PM
Fopen has evaded me. (PHP Problem) dholingw Programming 3 03-04-2005 12:29 PM
PHP fopen question ? antony_csf Programming 2 02-15-2005 05:16 AM
File Permission Error in PHP fopen() function tuka Linux - Software 2 08-12-2003 08:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration