我正试图在PHP中用简单的XML取回RSS。
浏览器网站说,如果你没有正确的用户代理人,你就会被阻止。
我如何确定用户代理人?
我正试图在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);
http://www.php.net/manual/en/book.curl.php rel=“nofollow”_cUrl,以检索这些饲料,然后使用simplexml_load_string功能,从包含内容的扼制式中创建DOM。 借助城市,你可以这样确定用户代理人:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
$content = curl_exec( $ch );
curl_close ( $ch );
$dom = simplexml_load_string($content);
And you can get a good example and a full code here: http://www.php.net/manual/en/ref.curl.php#93163
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) );
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 ...
<?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 = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
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 ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
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? 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 ...