dongliang1865 2015-10-23 07:56
浏览 115

使用php在iframe中使用移动模拟器加载跨浏览器站点

i'm trying to check and display a cross-browser site in an iframe to emulate a mobile environment. The iframe should display the website in mobile format. I have an iframe that is only 320px in width, some mobile sites that is loaded and using css for responsive layout works as expected. But for webbsites that uses other techniques for detecting mobile devices do not load correctly. I would like to catch them all. My major problem is the orgin for the sites, they differ an different url are loaded on specifik actions. I'm not developing a emulator for that purpose, I need to load these the urls to check if they are currently fully responsive.

I saw this site:

http://php-drops.blogspot.se/2013/07/mobile-emulator-with-php.html

But cannot get the hang of it. How can I load the true responsive site in my iframe? I suppose when the header tells the environment to load a different site, like m.site.com. If there is a unique mobile site that redirects how can I get that url?

  • 写回答

1条回答 默认 最新

  • duanen19871021 2015-10-23 21:48
    关注

    Got it working, this is what I did:

            $ch = curl_init();
        curl_setopt($ch, CURLOPT_TIMEOUT,               5);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,        false);
        curl_setopt($ch, CURLOPT_VERBOSE,               true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,        true);
        curl_setopt($ch, CURLOPT_HEADER,                true);
        curl_setopt($ch, CURLOPT_NOBODY,                true);
        curl_setopt($ch, CURLOPT_USERAGENT,             'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3');
        curl_setopt($ch, CURLOPT_URL,                       htmlspecialchars_decode($url));
        curl_setopt($ch, CURLOPT_HTTP_VERSION,      CURL_HTTP_VERSION_1_1);     
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,        true);
    
        curl_exec($ch);     
        $info = curl_getinfo($ch);
        curl_close($ch);
        return $info['url'];
    

    And I got the mobile url back. So in case of somewebsite goes to m.somewebsite or any other and includes the correct layout within the iframe :)

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序