简体   繁体   中英

Load cross-browser site with moblie emulator in iframe using php

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?

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM