现在PHP里判断浏览器是否是手机浏览器的方法一般是:
<?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);