如何掩盖你的PHP脚本作为浏览器? [英] How to disguise your PHP script as a browser?

查看:123
本文介绍了如何掩盖你的PHP脚本作为浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在使用网站的信息一段时间(网站允许,如果你提及源和我们做),我们已经手动复制信息。你可以想象这可能会变得很乏味,所以我一直试图通过使用PHP脚本获取信息自动化的过程。

We've been using information from a site for a while now (something that the site allows if you mention the source and we do) and we've been copying the information by hand. As you could imagine this can become tedious pretty fast so I've been trying to automate the process by fetching the information with a PHP script.

我试图的URL获取的是:

The URL I'm trying to fetch is:

http://mediaforest.ro/weeklycharts/viewchart.aspx?r=WeeklyChartRadioLocal&y=2010&w=46 08-11-10 14-11-10

如果我在浏览器中输入工作,如果我尝试file_get_contents()我得到错误的请求

If I enter it in a browser it works, if I try a file_get_contents() I get Bad Request

我想他们检查,看看客户端是否是一个浏览器,所以我滚动一个基于CURL的解决方案:

I figured that they checked to see if the client is a browser so I rolled a CURL based solution:

$ch = curl_init();

$header=array(
  'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12',
  'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'Accept-Language: en-us,en;q=0.5',
  'Accept-Encoding: gzip,deflate',
  'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
  'Keep-Alive: 115',
  'Connection: keep-alive',
);

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
$result=curl_exec($ch);

curl_close($ch);

我已经检查过,并且标题与浏览器的标题相同,但仍然得到 Bad请求

I've checked and the headers are identical with my browser's headers and I still get Bad Request

所以我尝试了另一种解决方案:

So I tried another solution:

http://www.php.net/manual/en/function.curl-setopt.php#78046

不幸的是这不工作,我的想法。

Unfortunately this doesn't work either and I'm out of ideas. What am I missing?

推荐答案

尝试转义您的网址,这对我有用。

Try escaping your URL, it works for me that way.

http://mediaforest.ro/weeklycharts/viewchart.aspx?r=WeeklyChartRadioLocal&y=2010&w=46%2008-11-10%2014-11-10

这篇关于如何掩盖你的PHP脚本作为浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆