0

I am attempting to show a cross domain website inside an iframe. I want to be able to display the mobile version of the website inside the iframe, though. I figured the best way to do this was to use something like this: https://stackoverflow.com/a/6630823/1022241 to spoof the user-agent.

I don't quite understand how I would use the above link / php to retrieve a site and put it in an iframe, though.

Community
  • 1
  • 1
  • Google or search SO for "PHP cURL". It's the best way to retrieve a remote document with options such as defining request headers (which you would need to do to specify a specific user-agent). –  Jan 26 '12 at 05:10
  • I guess I'm confused how a cURL server side will correspond to a document showing up client side. I'm guessing I won't be able to just hit this .php script with an xhr request –  Jan 26 '12 at 05:28
  • 1
    It will work just fine. Say your client .js makes an Ajax request to the server. The requested php file on the server then makes a cURL request to another site out in space while the client is still waiting patiently for its asynchronoous request to return. The php server receives the response from the third party and parses it or does whatever else you want then finally returns it to the original client to fulfill its request ... –  Jan 26 '12 at 14:20
  • If you want to post this as an answer I can accept it, worked great, thanks. –  Jan 29 '12 at 21:14
  • Answer posted. Glad it helped. –  Jan 29 '12 at 21:29
  • I suggest you to use Zend_Http_Client instead of cURL – dynamic Jan 29 '12 at 21:30

1 Answers1

0

You'll need to use PHP's cURLdocs bindings to retrieve the remote site's contents then send that back downstream to fulfill the Ajax request. Here's how it works:

  1. Your client .js script makes an Ajax request to the PHP script
  2. The requested php file on the server then makes a cURL request to another site out in space while the client is still waiting patiently for its asynchronoous request to return
  3. The PHP script receives the response from the third party and parses it or does whatever else you want then finally returns it to the original .js client to fulfill the request