Click here to Skip to main content
15,945,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Basically I have an iframe of an external site, which has html that is auto-generated.

What I want to do is to use file_get_contents to get the html within that iFrame, which is hosted on my domain.

So something like this:

PHP
<iframe src="othersite.com"></iframe>
<?php
$contents = file_get_contents(//iFrame Content);
?>

I would love someone to point me into the right direction.
Posted

You need to send an HTTP request to http://othersite.com, receive HTTP response from it and then deal with received data. To do it with HTTP, start here: http://www.php.net/manual/en/class.httprequest.php[^].

—SA
 
Share this answer
 
Alright friend,

I have used file_get_contents() to load my index.php file on my remote server onto my localhost and what I get as a result reveals that it will only fetch help you to display all the contents properly only if the webpage's all references are made absolutely rather relatively.

i.e. If the webpage you are trying to load via file_get_contents () has a stylesheet linked as
HTML
<link rel="stylesheet" type="text/css" href="./stylesheets/global.css" />

Then, you will have no luck displaying the page properly and probably you have to further process the page data loaded by you to somehow make all relative links to absolute links.

So, if the webpage you are loading has all absolute links like
HTML
<link rel="stylesheet" type="text/css" href="http://example.com/stylesheet/global.css" />
<script type="text/javascript" src="http://example.com/javascript/global.jquery.js" />

Then, the page will display correctly without any break...

Hope that it helped you. Mark as solved if it did :)

With Regards
Tushar Srivastva
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900