www.webdeveloper.com
Results 1 to 10 of 10

Thread: PHP Includes and iframes

  1. #1
    Join Date
    Apr 2005
    Location
    London
    Posts
    106

    Talking PHP Includes and iframes

    I would like to change the content of an area on my webpage when a user clicks on the menu.

    What is the most appropriate method to use PHP includes or frames??

    What are the pros and cons......

    Direction required for a newbie

  2. #2
    Join Date
    May 2005
    Posts
    327
    frames/iframes are really losing usefulness nowadays. Pretty much any realistic task you want to accomplish with them can be done efficiently without them - besides, some of the less mainstream browsers (such as Lynx/Links, text based browsers - VERY GOOD text based browsers ) don't support frames, styles, or any of that extra stuff - they are designed to display content only, focusing on accessability over attractiveness. Frames cause extra problems, because if your browser doesn't support frames, you can't view the site. Period. Not the case with CSS or styles - if the browser doesn't support it, the content still shows up, minus pretty formatting.

    Frames tend to disrupt the flow of content, which makes it hard for people with disabilities to use your site (IIRC it affects text readers for the blind, and keyboard navigation with frames is a hassle too).

    PHP Includes are something completely different - it allows you to just include a separate file into the normal flow of the site, and is controlled by the server rather than the client. For instance, when you request a site with PHP (or SSI) includes in the code, you don't actually know it - all you see is the final product in the source code, not the PHP or SSI stuff.
    Administrator of The Engine Network
    http://www.the-engine.org
    "We are drunk of borg. Resistance is floor-tile."

  3. #3
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,972
    PHP includes:
    • accessable
    • search engine friendly
    • doesn't bring up bookmarking issues
    • doesn't require whole other documents

    Iframe:
    • Easier for you
    • Tiny bit faster

    PHP all the way IMO
    Disclaimer. (1) Whilst I will help you sometimes, if I feel like it, and my advice in relation to your actual question will be of good quality: my posts are to be taken with a pinch of salt. I will be sarcastic, deploy irony and include obscure cultural references for my own amusement without warning.
    (2) You will gain nothing from complaining, and if you try to argue with me then you will not win. No matter how noble your battle seems, I am still better than you, don't be an hero.

  4. #4
    Join Date
    Apr 2005
    Location
    London
    Posts
    106

    Talking

    Thank goodness I've made the right choice in choosing to use php includes which I found actually quite easy to use (I must have done something wrong :-) )

    I have another question regarding PHP includes - the tutorial I used suggested creating a new index page for each new page I wanted to pull thorough the site e.g.

    head.htm
    index.php
    menu.htm
    footer.htm

    so if I want to add booking_forms I need to add booking_forms.php and booking forms.htm

    is there anyway of cutting out the .php file??

    link to the site I'm working on http://www.**********.co.uk/pioneer/index.php

    Please keep it simple, up until an hour ago I hadnt touched php.

    Cheers to all.

    Si

  5. #5
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,972
    You could have one PHP file for each page, in which case the php file would consist of what's different and would include what's the same.

    Or you could have one PHP file for every page wich would consist of what's the same, and include what's different.
    Disclaimer. (1) Whilst I will help you sometimes, if I feel like it, and my advice in relation to your actual question will be of good quality: my posts are to be taken with a pinch of salt. I will be sarcastic, deploy irony and include obscure cultural references for my own amusement without warning.
    (2) You will gain nothing from complaining, and if you try to argue with me then you will not win. No matter how noble your battle seems, I am still better than you, don't be an hero.

  6. #6
    Join Date
    Apr 2005
    Location
    London
    Posts
    106

    Talking

    Thanks Tree...I think.

    I thought there might be a clear bit of php which would negate the need to reproduce the php page for every new html page.

    something like:

    click button 1 goto html content1
    click buttom 2 goto html content2

    but all in the same php page

    Am I making sense? I've seem this type of thing on other sites and wondered if the php searched for the appropriate html page??

    <a href="br.php?page=faq">
    Last edited by SimonBahr; 07-09-2005 at 07:06 AM.

  7. #7
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,972
    O.k. lets say your going to have one php document and you're going to call it index.php, then all of your content can be in include files in a folder called content.

    index.php would be stuff like doctypes and head infomation, with a tiny little script to include a file based on the url (e.g. index.php?page=foo).

    You'd start with the plain HTML that you want all your documents to start with.
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>The Pages of Doom</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
    <meta name="keywords" content="Pages, Doom">
    <meta name="description" content="Many pages, all with doom included.">
    <link href="stylesofdoom.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <div id="container">
    This would be the script. It takes from the URL, makes a file path out of it and includes that file.
    If it were given index.php?page=foo then it would include content/foo.inc.
    PHP Code:
    <?php
    if (isset($_GET['page']))
    {include 
    'content/'.$_GET['page'].'.inc';}
    else
    {include 
    'content/default.inc';}
    ?>
    In the event of not being given a page, it'll just go for a default file.
    Then you'd finish up, often with a lot of closing tags.
    HTML Code:
    </div>
    </body>
    </html>
    You can then link between these dynamic documents like so:
    HTML Code:
    <a href="?page=foo">
    Last edited by the tree; 07-09-2005 at 09:13 AM.
    Disclaimer. (1) Whilst I will help you sometimes, if I feel like it, and my advice in relation to your actual question will be of good quality: my posts are to be taken with a pinch of salt. I will be sarcastic, deploy irony and include obscure cultural references for my own amusement without warning.
    (2) You will gain nothing from complaining, and if you try to argue with me then you will not win. No matter how noble your battle seems, I am still better than you, don't be an hero.

  8. #8
    Join Date
    Apr 2005
    Location
    London
    Posts
    106
    Hi Tree,

    Thank you. I think what you're saying is that my contents includes in my index.php should be replaced with this new script which will fetch the appropriate page from the content folder based on the url.

    I noticed that your foo page did not have an .htm/.html extension and has .inc. What is the relevance?

    Cheers Si.

  9. #9
    Join Date
    May 2005
    Posts
    327
    It doesn't really matter what extension it is, however a number of web developers use .inc to specify a file as an include - makes organization a little easier.
    Administrator of The Engine Network
    http://www.the-engine.org
    "We are drunk of borg. Resistance is floor-tile."

  10. #10
    Join Date
    Apr 2005
    Location
    London
    Posts
    106

    Talking

    Thanks to all.

    This exactly what I was looking for.....tried, tested and now up and running.

    Many thanks Si

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles