Including PHP in HTML with IFrames

Related Articles

This Article will show you how to include a PHP file inside an HTML file seamlessly, using inline floating frames. Iframes are simple floating frames (HTML TAG), which can be placed at any required location on an HTML file. Iframes are said to be faster rendering; use less memory, and are faster at scrolling. They can be stacked over other inline floating frames and can contain transparent content.

Iframes have an important attribute called src which acquires the filename to load inside the Iframe. Using this attribute, you can specify the PHP file to load inside the IFRAME. The page will then render as if an HTML file were executed.

Let us see one example where this technique is applied:

This technique is applied in many areas, one example is a news portal, which usually generates a static HTML file as its homepage and other content pages, to save the bandwidth and cope with the heavy load on the site.

There is a location where breaking news is updated. Applying the PHP in HTML technique will be very useful, in this case, where the PHP file might dynamically perform a dynamic operation to fetch the dynamic content form a database or other location. Using IFRAMEs we can achieve this type of effect.

Let me explain practically how this works out

Let us create two files namely:

  • Test.htm
  • Test.php

Source Code for Test.htm

<META HTTP-EQUIV="Refresh" CONTENT="5; URL=test.php">
<html>
<head>PHP in HTML<head>
<body>
<h2><font face="arial" color="green"></font></h2><br><br>
<Iframe src="Test.php" width="300" height="600"></Iframe>
</body>
</html>

Source Code for Test.php

<?phpinfo();?>

Description: Test.htm contains a meta refresh tag which is used to refresh the page inside the IFRAME: the Test.php file.

Next we have the Iframe tag containing the attribute: src="Test.php". This sets or retrieves a URL to be loaded by the object Iframe.
Width and height attributes specify the width and height of the Iframe in pixels or as a percentage.

Coming to the Test.php, the PHP script: <?phpinfo?> displays the PHP configuration file.

Put the files in your web server root folder (ie wwwroot folder)

Now run the Test.htm, you will be able to see the Test.php loaded inside the Iframe, on the Test.htm

You are done now.


Publication Date: Wednesday 15th October, 2003
Author: G.ajaykumar View profile

Related Articles