Log in

View Full Version : php instead of iframe



chechu
08-18-2008, 03:17 PM
It seems that using an iframe is not the best option. But to avoid having to adapt every page of my site when I have an update, I need a page that I just need to adapt once, and all pages take over the content. This is easily done with an iframe, but is it possible to do it in other ways, like with php ?
Thanks !

mburt
08-18-2008, 03:22 PM
Well, a simple way is this:


<?php
include "pagedirectory/".$_GET["q"].".htm";
?>

So the page URL that loads that particular page is like this:

http://www.mywebsite.com/?q=somepage

^^ This loads "pagedirectory/somepage.htm" into the desired area.

chechu
08-18-2008, 03:30 PM
So if I wish to include 'content.html' in 'index.html', which are saved in the same directory, I add this, renaming the page 'index.php'

<?php
include "".$_GET["q"].".html";
?>
Don't really get it.

mburt
08-18-2008, 03:35 PM
$_GET["q"] is the result of the variable "q" in the url.

So if http://www.mysite.com/?q=mypage

$_GET["q"] represents "mypage". You pass the variable and use the "include" keyword which includes the desired page in your page.

If you wanted to include content, you'd do this:


<?php
include "content.html";
?>

However, if you want your pages to be dynamic, use the script i posted originally.

chechu
08-18-2008, 04:55 PM
However, if you want your pages to be dynamic
What do you define dynamic ?
In your example, I should use this, correct ?

<?php
include "".$_GET["q"]."content.html";
?>
Should there not be a height and width defined, as in an iframe ?
I just want to place updates in it and a few images of events or exhibitions, at the side of my site.

djr33
08-18-2008, 05:54 PM
<?php include "page.html"; ?>

That's all you need. That works just like an iframe. Adding the GET variable into it is making it more complex than an iframe, though it might help you too.

In other words:
<div setup-like-your-iframe-size-etc><?php include "iframeurl.html"; ?></div>

That would accurately replace an iframe.

chechu
08-18-2008, 06:14 PM
Thanks to both.
Why is an iframe not the best option ? Is this php better, or equal, or a matter of taste ?


<div setup-like-your-iframe-size-etc><?php include "iframeurl.html"; ?></div>

Should the page that has the above code have .php as extension ?

rangana
08-19-2008, 01:19 AM
Thanks to both.
Why is an iframe not the best option ? Is this php better, or equal, or a matter of taste ?

You might find it a learning to read Why are frames evil? (http://www.html-faq.com/htmlframes/?framesareevil).

Though frames and iframes differ in a way, they still work the same.
The content within an iframe is not part of that page, it's part of another. And so a search engine will not be looking at the content of the iframe as a part of the parent url that holds the iframe.




<div setup-like-your-iframe-size-etc><?php include "iframeurl.html"; ?></div>

Should the page that has the above code have .php as extension ?

Yes, it should be saved as *.php.

Twey
08-19-2008, 01:49 AM
Quite apart from search engines, the <iframe> has serious usability problems and is no longer a part of the HTML specification.

Note that a server-side language is not a direct replacement for frames (nor intended to be). There are many things that one can do with a server-side language that one cannot do with frames, and a few things that one can do with frames that one cannot do with a server-side language alone (I recommend Javascript/XMLHttpRequest for these rare cases, but be sure to provide a fallback).

djr33
08-19-2008, 03:55 AM
Oh, and by the way, the major difference here is that it will include it into the code, so the included page can't have a head section, etc. It'll just need to be more body stuff.

chechu
08-19-2008, 09:55 AM
Works perfectly. Thanks so much !!