English 中文(简体)
简 计 用户代理人
原标题:SimpleXML user agent
  • 时间:2011-11-13 19:51:18
  •  标签:
  • php

我正试图在PHP中用简单的XML取回RSS。

浏览器网站说,如果你没有正确的用户代理人,你就会被阻止。

我如何确定用户代理人?

问题回答

PHP有user_agent 规定你可以(临时)使用:

ini_set( user_agent ,  user_agent_goes_here );

它还载于php.ini。 (如果您从这里更改,将永远不变)

例:

//Setting the user agent as Firefox 9.0
ini_set( user_agent ,  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20100101 Firefox/9.0 );
$xml = file_get_contents($rssfeed);
$simplexml = simplexml_load_string($xml);

You can do so with cURL using the CURLOPT_USERAGENT argument.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/rss.xml");
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); //$user_agent would contain your agent.
$xml = curl_exec($ch); //xml stored in the variable $xml
curl_close($ch);
?> 

简言之, 你派一名用户-代理人。

长期以来的答案是,你将需要使用一种PHP方法,在吉大港山区(可能是可治愈的)取暖内容,以启动连接,发送预期的头盔,并 down掉你试图以身着的XML档案。 一旦完成这项工作,就将检索的数据与你选择的XML教区划。

例如,将Curl编成IE 6:

curl_setopt($curl, CURLOPT_USERAGENT,  Mozilla/6.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0) ); 




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签