Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: php instead of iframe

  1. #1
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default php instead of iframe

    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 !

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Well, a simple way is this:

    Code:
    <?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.
    - Mike

  3. The Following User Says Thank You to mburt For This Useful Post:

    chechu (08-18-2008)

  4. #3
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    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'
    Code:
    <?php
    include "".$_GET["q"].".html";
    ?>
    Don't really get it.

  5. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    $_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:

    Code:
    <?php
    include "content.html";
    ?>
    However, if you want your pages to be dynamic, use the script i posted originally.
    - Mike

  6. #5
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    However, if you want your pages to be dynamic
    What do you define dynamic ?
    In your example, I should use this, correct ?
    Code:
    <?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.

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    <?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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. The Following User Says Thank You to djr33 For This Useful Post:

    chechu (08-18-2008)

  9. #7
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Thanks to both.
    Why is an iframe not the best option ? Is this php better, or equal, or a matter of taste ?

    Code:
    <div setup-like-your-iframe-size-etc><?php include "iframeurl.html"; ?></div>
    Should the page that has the above code have .php as extension ?

  10. #8
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Quote Originally Posted by chechu View Post
    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?.

    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.

    Quote Originally Posted by chechu View Post
    Code:
    <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.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  11. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  12. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •