How to modify HTTP_USER_AGENT, disguise the web browser as a mobile browser, and finally edit the post by Youritumei_habataku from 2011-11-am. in PHP, the method for judging whether the browser is a mobile browser is generally: & lt ;? Phpphp determines whether the client is a mobile phone $ agent & nbsp; $ _ SERVER [how to modify HTTP_USER_AGENT and disguise a web browser as a mobile browser
This post was last edited by Youritumei_habataku at 17:10:45, 2011-11-10
In PHP, the following methods are generally used to determine whether the browser is a mobile browser:
// Php determines whether the client is a mobile phone
$ 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 ");
?>
If it is a web browser, he will add a code so that he cannot display the page to be displayed, I would like to ask if PHP could modify its $ _ SERVER ['http _ USER_AGENT '] value and disguise itself as an iPhone or other mobile browser, in this way, I can obtain the website's mobile phone webpage content on my computer. the code is as follows:
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 );
Thank you.
------ Solution --------------------
Use firefox to install the User Agent Switcher extension, which can simulate the ua header access sent by the mobile phone
------ Solution --------------------
Sorry, I have not carefully read the problem.
$ User_agent = my mobile phone '';
Curl_setopt ($ ch, CURLOPT_USERAGENT, $ user_agent );