monkeytooth Posted June 13, 2011 Share Posted June 13, 2011 I'm not entirely sure if this is doable with solely PHP but I figured I'd at least ask I want to target specific pages of mine and display them in an iframe, that generally I would assume is the easy part iframes are essentially easy like that. However what I want to do is figure out how I can manipulate the fetching of the page if you'll call it that. So that when the page renders in the iframe it renders under the User Agent I would give it, and not the browser I am currently using. What I am trying to do is view a handful of my sites currently that have mobile detection. To see how they display in a mobile device outside of the one I own. I own an android phone so I want to see how it looks through lets say an iphone, ipad etc. I know the browser will render the page properly no matter what, that's not so much the concern as sizing things properly and making sure they sit right within the constraints given by the devices view pane. So, what would I want to do in order to try and pull that off? Would I cURL to the page get the contents based off then load the source into a temp file on my server? or is there a way I could do it like that without cURL. Also note some of the pages I do the detection of mobile devices is transparent and will only trigger an alternative output to those devices there's no separate URL to go to like m.domain.com that will display it regardless this is a partial reason why I want to have this iframe bit. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 13, 2011 Share Posted June 13, 2011 Well, in my opinion, and I would say the vast majority of people knowledgeable in web development, you shouldn't be using IFrames at all - even if the site is meant only for typical web browsers on a computer. One method of having a site display differently based upon the type of device is the CSS media property. You create the content in a generic fashion and determine the display of the output using CSS style sheets. Within the style sheets you can specify different style properties based on the media (screen, handheld, print, etc.). But, if you wrap content inside an IFrame, the CSS can't "fix" that for a handheld device. Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted June 13, 2011 Author Share Posted June 13, 2011 Your right, Im not a big fan of iframes myself either. Also my question isn't geared towards the design and development of the actual mobile version of the site. The question is geared at how can I trick the site into thinking I am a mobile device, without actually viewing the site through a browser thats actually part of a mobile device. I want to type for example http://mydomain.com/?view=myothersite.com into my browser. Use the get value from view as a means to trigger wahts loaded into the iframe itself or even the page itself it doesn't matter this is all about personal use over anything else. As I said some of the stuff I design/develop is only triggered for view by a mobile device, which would be rendered view user agent detection. So I am figuring if theres a way I can "surf" to the page via my browser and some scripting to make it think I am on a mobile device when in fact I'm not and just size up the page so it matches the size of the viewing pane on any given device. I know the pages will actually render on the device differently based on its level of built in support for the CSS an all else but as I mentioned before that factor is not my concern right now. Just viewing it within constraints (size) of the screen on a device is all I care about right now. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 13, 2011 Share Posted June 13, 2011 The question is geared at how can I trick the site into thinking I am a mobile device, without actually viewing the site through a browser that's actually part of a mobile device. Simple. If you are using User Agent as the means to determine when to show "mobile" content. Then just check for the value on the query string you are using to "trick" the system and hard code the user agent value if(isset($_GET['view']) && $_GET['view']=='myothersite.com') { $_SERVER['HTTP_USER_AGENT'] = 'some_mobile_device_value'; } Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted June 13, 2011 Author Share Posted June 13, 2011 Will that work with getting that same site to show as if it we're that browser? Right now closest thing I've come to is trying something with cURL to achieve both.. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 13, 2011 Share Posted June 13, 2011 As long as you check the GET value and explicitly set the values that you are checking to determine mobile or PC, yes it will work. Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted June 13, 2011 Author Share Posted June 13, 2011 Ok, so I guess I just confused myself entirely.. Im having troubles with the cURL concept of getting the page to load/render through my php file. Im trying to ultimately load the iframe where the src of the iframe is like that "view" variable I made note of earlier. Where the php file is on my server and then loads the the page of choice into the iframe and the php file is the piece that is swapping the user agent out from what the browser is to what I want it to be. My attempts with cURL have been far from fruitful so I am wondering now is cURL my go to option. I know I can try fopen, but my understanding of fopen is that in what I want to attempt to do its not always the best option to go with as some servers reject it. Maybe I am approaching the curl method the wrong way. below is what I am attempting to do with curl. Maybe I am off? function curl_download($Url){ // is cURL installed yet? if (!function_exists('curl_init')){ die('Sorry cURL is not installed!'); } // OK cool - then let's create a new cURL resource handle $ch = curl_init(); // Now set some options (most are optional) // Set URL to download curl_setopt($ch, CURLOPT_URL, $Url); // Set a referer curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com"); // User agent curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"); // Include header in result? (0 = yes, 1 = no) curl_setopt($ch, CURLOPT_HEADER, 0); // Should cURL return or print out the data? (true = return, false = print) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Download the given URL, and return output $output = curl_exec($ch); // Close the cURL resource, and free system resources curl_close($ch); return $output; } print curl_download('http://www.monkeytooth.net/'); Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted June 13, 2011 Author Share Posted June 13, 2011 http://mobilewebsites.com/mobile-preview/ is primarily an spot on example of what I want to recreate, but I don't want to have to go to there site every time to do what I want to do, and I want to elaborate on it some as well. My current example is http://chrishacia.com/demo/try/browseragent.php?v=example.com but its running it to issues it only half works, example if I go to mp3.com or tacobell.com with mine I get issues about object moved. or if I go to facebook.com I get issues where nothing is displayed at all. However if I use the link that shows what I am trying to do and go to the same urls they actually work. So this is turning into more of a question of how should I handle this better? I am fairly new to curl, I can't seem to make the alternative $_SERVER['HTTP_USER_AGENT'] = 'some_mobile_device_value'; concept work. So any idea's? Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted June 13, 2011 Author Share Posted June 13, 2011 I figured it out, I was approaching what I was doing all wrong and being a novice with cURL in specific that didn't help much either. I appreciate the efforts set for as they did send me in the right direction. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.