PHP: render iframe on the server side - php

I understand that an iframe is rendered by the browser engine
is there a way to render the full HTML on the server side and serve it to the front end?
I tried the PHP's file_get_contents() function and the srcdoc attribute for the iframe
This simply downloads the content of the page and makes it unusable
<?= file_get_contents('http://dns_blocked_by_isp.com'); ?>
And this renders a non-working iframe
<iframe srcdoc="<?= file_get_contents('http://dns_blocked_by_isp.com'); ?>"
frameborder=0 width=510 height=400 scrolling=no
allowfullscreen=allowfullscreen>
</iframe>
So am basically looking for an alternative of runat="server" in ASP.NET but for PHP if possible
Motivation:
My ISP blocked the DNS address where I get my iframe source from, but my server runs on a different region which means it can download the content just fine and the urls in the iframe has -cdn.com suffix which in turn is not blocked by the ISP
Thank you

To get around browser support issues, you'd probably be better off setting up a PHP proxy page (i.e. a script on your server that just fetches the remote page and serves the source directly as a page from your server), but I suspect that the issue you're running into is just that the " characters being returned from the remote page are breaking the srcdoc attribute. Let's say that the remote file looks like:
<p class="worldclass">Hello World</p>
Then your example would result in:
<iframe srcdoc="<p class="worldclass">Hello World</p>"
So the the value of srcdoc is just <p class=
You just need to escape the code appropriately:
<iframe srcdoc="<?= htmlspecialchars(file_get_contents('http://dns_blocked_by_isp.com')); ?>"
frameborder=0 width=510 height=400 scrolling=no
allowfullscreen=allowfullscreen>
</iframe>

Related

Loading external webpage into my page without redirecting to different URL

So what I want to do is create a subdomain on my website and have it load an external website into it without actually going to that website. For instance:
google.mydomain.com loads google.com but the URL bar reads google.mydomain.com.
How do I go about doing this?
I tried this but could not figure it out.
Trying:
iframe
I want page to take up the whole screen for each person's computer. Can I set it to 100% instead of x amount of pixels?
I want to remove scroll bars but it says not supported.
You can use either an Iframe, or file_get_contents();
Iframe:
<iframe src="http://google.com" style="width: 100%; height: 100%;">
file_get_contents():
<?php
echo file_get_contents('http://google.com');
?>
With file_get_contents(), you need to beware of the website you're fetching from using relative URL's, which will break the CSS, Images, Javascript, etc.
You are not going to be able to use php's include function, as this is not a resource residing on your server.
One option you could explore is loading everything in as the contents of an iframe: see http://www.w3schools.com/tags/tag_iframe.asp for some details about the iframe html element
iframe is now not supported in html5
it works on html5 also
Easy to add or remove
Example:
<body onload="window.location.href='https://www.google.com/'"> </body>

Dynamic PHP images requesting url

I have a PHP script that generates dynamic images using GD. The image may be accessed remotely via, for example, http://mysite.com/scripts/phpimages.php
Any remote website such as example.com could able to render this image in its client side HTML img tag. For example:
<!-- http://example.com/about.html -->
<img src="http://mysite.com/scripts/phpimages.php" />
What I need that my script able to know the URL of the image requested page i.e http://example.com/about.html
Use this
echo $_SERVER['HTTP_REFERER'];
To prevent errors,
if(isset($_SERVER['HTTP_REFERER'])) {
echo $_SERVER['HTTP_REFERER'];
}

iframe php injection into my html site

I have quite a small website, with a total of 3 webpages, consisting of only html, css and jquery...now on one of my .html pages, I have this annoying iframe injection (the source file is php) that is added on top of my body tag each time i load my page. Now I deleted all my referenced stylesheets, plugins etc one by one but the only way get rid of it is if I delete all my content for that page. How do I get rid of this iframe? Any tips?
Note that the same plugins I used on my other pages I used on this 'hacked page', except for one plugin...but removing that one plugin does not fix it...?
Here is the iframe code I got by inspecting the element: this whole part below is injected
<div style="padding-left: 120px;">
<iframe width="728" scrolling="no" height="90" frameborder="0" allowtransparency="yes" src="http://b.admedia.com/banner.php?id=18793&sr=1&injection_code=true&subid=FC&ip=[IP]&ua=[UA]&transparency=[TR]&highlight=0&style=1&appnxsId=860932&size=728x90&search=digital cameras&force=1&ref=&bpage=">
<html>
<head>
</head>
<body>
</body>
</html>
</iframe>
</div>
You almost certainly have malware on your PC.
For example, see this and this. Most likely you have a trojan that is injecting the code into explorer, enabling the attacker to farm for ad clicks.
You can confirm by trying a different browser or running a virus/malware scanner.

Loading external website with PHP file

I'm using JQuery to resize an iframe to make it have the same height as it's content, it works perfectly though it only works if the content is in the same domain.
I need to display external content so I'm making the iframe point to a file in my server which in turn should display the external content:
<iframe src="frame.php" scrolling="no" frameborder="0" noresize="noresize" style="width:100%; border: 1px solid black;">
How do I make frame.php display the content of the external domain?
In case you need more info here is the answer on how to do it (he explains everything excepts how to display content in the php file):
AutoHeight IFrame
Thanks
So you want to fetch the contents of an external site?
This will work, but it'll break the layout when the target page has non-absolute URLs and relative links:
frame.php:
<?php
echo file_get_contents($_GET['url']);
?>
<?php echo file_get_contents( "http://example.com" );?>
Somethhing like that will do
Unfortunately, php isn't the correct language to be doing this. In order to determine the height of the document in the iframe, you would need to make a javascript call from the parent document (where the iframe element is) to the document referenced in the src of the iframe.
In the case where the src of the iframe is on your domain, you have full permission to use the DOM of the document to get the document's height, as per the same origin policy. When you load a document from another domain, you do not have permission to query for the height. What the answerer of your question seems to be suggesting is setting up a proxy on your site so that the same origin policy would be circumvented.
However, there going to be other issues with that (ie relative links on the proxied page, etc.)

Finding embed site for a flash app

Heyas. I have an flash app that I'm working on that can be embedded on other websites (like YouTube videos), but we want to know what website the user is viewing the site on. Is there any way to tell what site the app is embedded on that the user is viewing on?
The original app is written in flash/actionscript and php running on the server, if that helps. Thanks.
You can simply retrieve the HTTP referrer header via php, store it somewhere and than serve your flash content...
<?php
// served from http://yoursite.net/your_flash.php
//read the referer header
$referer_url = (isset($_SERVER['HTTP_REFERER']))? $_SERVER['HTTP_REFERER'] : "";
//store it somewhere...
//read the swf file
$swf=file_get_contents('flash_app.swf');
//spit the flash content out with the proper header
header('Content-type: application/x-shockwave-flash');
echo $swf;
?>
Embed code, to be pasted by third party websites in their HTML:
<object width="550" height="400">
<embed src="http://yoursite.net/your_flash.php" width="550" height="400">
</embed>
</object>

Categories