Home  >  Article  >  Backend Development  >  怎么修改HTTP_USER_AGENT,把网页浏览器伪装成手机浏览器

怎么修改HTTP_USER_AGENT,把网页浏览器伪装成手机浏览器

WBOY
WBOYOriginal
2016-06-13 11:09:571953browse

如何修改HTTP_USER_AGENT,把网页浏览器伪装成手机浏览器

本帖最后由 Youritumei_habataku 于 2011-11-10 17:10:45 编辑 现在PHP里判断浏览器是否是手机浏览器的方法一般是:
//php判断客户端是否为手机
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent,"NetFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS"))
header("Location:http://bolg.malu.me/photo/wap-mini/index.php");
?>

如果是网页浏览器,他会加个代码,让他显示不出要显示的网页,我想问问PHP里面有没有可能修改自己的$_SERVER['HTTP_USER_AGENT']值,把自己伪装成一个iPhone等手机浏览器,从而在电脑上能获取这个网站的手机网页内容,我是这样获取代码的:
ob_start(); 
$ch = curl_init(); 
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt( $ch, CURLOPT_POST, 1 ); 
//curl_setopt( $ch, CURLOPT_POSTFIELDS, $param ); 

//curl_exec( $ch ); 
//$retrievedhtml = ob_get_contents(); 
$retrievedhtml=curl_exec( $ch ); 
ob_end_clean(); 
curl_close( $ch );

谢谢
------解决方案--------------------
用firefox安装User Agent Switcher扩展,可以模拟手机发送ua头访问
------解决方案--------------------
sorry,没仔细看问题

$user_agent = 我是手机'';

curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn