Website like frames but without is it doable?

Discussion in 'Programming & Software Development' started by Revenger, Nov 1, 2008.

  1. scythe

    scythe Member

    Joined:
    Aug 15, 2002
    Messages:
    179
    Location:
    Brisbane
    PHP:
    </head>
    <body>
    <div id="page">
    <div id="head">
    <?php include ("template/header.html"?>
    </div>
    <div id="menu">
    <?php include ("template/menu.html"?>
    </div>
    <div id="content">
    <?php
        
    switch ($_GET['page']) {
            case 
    "page1":
                include(
    "page1.php");
                break;
            case 
    "contact":
                include(
    "contact.php");
                break;
            case 
    "something":
                include(
    "anything.php");
                break;
            default:
                include(
    "myDefaultContent.php");
        }
    ?>
    </div>
    </div>
    </body>
    </html>
     
  2. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Thanks will try it out at the earliest chance i get :D
     
  3. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Thanks scythe just tested it works great thanks for that explanation about the comma in css earlier which i must have overlooked earlier as I was probably tired.

    Just what I was looking for a way to update the index without having to replicate the index for every page on the site.
     
  4. Mr_LeE

    Mr_LeE Member

    Joined:
    Jun 24, 2006
    Messages:
    224
    Location:
    Sydney
    After reading this I might learn CSS and JS in the summer.
     
  5. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Looks like this thread inspired you.

    And for everyone that helped me get this far thanks.

    Here is the full current template now of all my cleaned up work from everything I've grabbed, used etc for anyone on ocau and beyond to use.

    Template

    Feel free to give me feedback on it.

    EDIT: The stylesheet I'm looking at for the background properties etc so a more complete template with fixed up will come later.

    Edit 2: Template fixed up with the 2 tone colour and is up, google pages says its version 4 cause I uploaded it thought it was uploaded twice when it said version 2 so tried to remove it (update 3) then add a new one in (update 4).

    This minor update fixes up the non 100% width colour in the style sheet so you can create that 2 tone look that blogs and other sites use where you have a fixed width in the center of ??px with its own page height background colour.

    To get a 2 tone site look: in the main styles.css stylesheet

    Change the #page width from 100%
    Uncomment out the background colour in #page and change to what colour you want your center area to be.
    Change the html,body background colour from white to whatever colour you want your sides.
    And now you have a 2 tone colour page template.
     
    Last edited: Nov 6, 2008
  6. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Bringing this topic out of archive as I'm going to be working on the site again as I need a html site for my course and this fits basically.

    When i tried it just now i got this.

    Code:
    Notice: Undefined index: page in E:\wamp\www\index.php on line 27
    Which is this line:

    Code:
    switch ($_GET['page']) {
    I think its because I'm just using /index.php with no ?page path.

    But it still shows the page ok just that message above it

    Changed it to:

    Code:
        $page = (isset($_GET['page']) ? $_GET['page'] : ''); 
        switch($page) {
    and the error went away.
     
    Last edited: Jul 14, 2009
  7. scythe

    scythe Member

    Joined:
    Aug 15, 2002
    Messages:
    179
    Location:
    Brisbane
    Yep, you fixed that the correct way and you were right about the cause of it too.
     
  8. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Ahhh thanks just happened to come across it doing allot of googling didn't know if it was the correct way.

    Well you can see the actual site 'being worked on' at the moment on at my dyndns here which is this pc I'm typing on and webserver is only up sometimes.

    Last menu link 'Whatever Chan' is a actual Chan board I installed to test and it does work and yes you can post on it :D
     
  9. wwwww

    wwwww Member

    Joined:
    Aug 22, 2005
    Messages:
    6,270
    Location:
    Bangkok
    Yes, use tables and css property overflow:scrolling (iirc - google to confirm).
     
  10. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Huh I don't understand this comment what post was it referring to in the thread?

    As I revived my post from oct last year now I've gotten back into it again.

    Its using a PHP switch method with seperated pages which is working well.

    Id love to learn mySQL to replace the static pages with a database.

    Is there a way to change the left page based on the main body page?

    In my body before the switch is this.

    Code:
    <div id="menu">
    <?php include ("template/menu.html") ?>
    </div>
    Say if I load xxx page in my body the menu changes to xxx menu.

    I presume this is doable somehow with this format.
     
    Last edited: Jul 15, 2009
  11. scythe

    scythe Member

    Joined:
    Aug 15, 2002
    Messages:
    179
    Location:
    Brisbane
    Yep, you could do a similar thing. Just move the line where you set the $page variable to above the menu so that you don't get the same error message.

    PHP:
    <div id="menu">
    <?php 
    $page 
    = (isset($_GET['page']) ? $_GET['page'] : '');
    include (
    "template/menu.php?page=$page");
    ?>
    </div>
    I think that should work right. Then in menu.php you would be able to add
    PHP:
    <?php
    $page 
    = (isset($_GET['page']) ? $_GET['page'] : '');
    ?>
    and be able to modify the menu based on what page you were on.

    Have a play around with it. You should be able to get it working how you want based on what you've done already.
     
  12. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Thanks for that code I cant try it as I'm not home.

    Just wondering where Id pull the menu pages from with a include and cases?

    As template will be the template directory for presumably pulling from say /menus/menu-page.html
     
  13. scythe

    scythe Member

    Joined:
    Aug 15, 2002
    Messages:
    179
    Location:
    Brisbane
    You can store the menu.php page where ever you'd like, but yes, you probably want to store it in the templates directory.

    You have a few options for how you want to do the menu.php page/s. You can either have a single menu.php file (I'll explain soon), or multiple menu_page.php files.

    If the menu's are going to be mostly the same then it would make sense to have a single menu.php file (to save code duplication - why have the code for a home, login, about etc link in 7 different files), however, if the menu's are going to be mostly different, then you could have separate files. It's completely up to you on how you want to do it.

    If you had a single menu.php file, then it might look something like:
    PHP:
    $page = (isset($_GET['page']) ? $_GET['page'] : '');

    echo 
    '<a href="/">Home</a>'// Home link in every menu
    if ($page == '')
    {
    echo 
    '<a href="something.html">Something</a>'// Only show this link if we are on the home page (ie. no $page variable blank)
    }
    if (
    $page == 'about')
    {
    echo 
    '<a href="blah.html">Blah</a>'// Only show this link if we are on the about page (ie. $page variable is blah)
    }
    if (
    $page == 'about' || $page == 'contact')
    {
    echo 
    '<a href="something.html">Something</a>'// Only show this link if we are on the about or contact pages (ie. $page variable is about or contact)
    }
    if (
    $page !== 'about' || $page !== 'contact')
    {
    echo 
    '<a href="something.html">Something</a>'// Only show this link if we are NOT on the about or contact page (ie. $page variable is not about or contact)
    }
    So with that you should be able to build a menu.php file that shows the menu that you want based on what page you are on. If you were going to have multiple menu_page.php files then in your main php file, where you would include the menu you would do a switch on the $page variable and include the appropriate menu_page.php file (in the same sort of way as you include the content.

    Hope this helps. Just have a play around and see how you go. You may need to play around with the paths in the includes to make sure that you are getting the right files.
     
  14. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    That poped up a error message in the menu.

    PHP:
    Warning: include(template/menu.php?page=) [function.include]: failed to open streamNo error in E:\wamp\www\index.php on line 23

    Warning
    : include() [function.include]: Failed opening 'template/menu.php?page=' for inclusion (include_path='.;C:\php5\pear'in E:\wamp\www\index.php on line 23
     
  15. scythe

    scythe Member

    Joined:
    Aug 15, 2002
    Messages:
    179
    Location:
    Brisbane
    Without looking into it too much I would guess that it's using the wrong paths. Try lpaying around with the include path (try without the template/ try a ../ first etc). Or you could try to work out what it should actually be. You are trying to work out the path to the menu.php file from the file that is trying to include it.

    For instance, if the file doing the including is index.php and it's located in root and menu.php is located in template/ then you should use include('template/menu.php'). If index.php is in template/ and menu.php is in template/ then you should use include('menu.php').

    Hopefully that makes sense.
     
  16. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Had another play and still not going.

    I think its the statement for including the dynamic menu

    As the normal code works fine of:

    PHP:
    <div id="menu">
    <?php include ("template/menu.html"?>
    </div>
    So looks to be somewhere in the rest of the statement you had.
     
  17. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Pulled the site back out again as Ive been working on another section of it.

    Want to change the switch includes to a dynamic system like this I have the following code but has the undefined index problem.

    If it didn't have that prob it would be ok.

    PHP:
    // Set $page to "home.txt" if a parameter isn't passed
      
    if ($_GET['page']) {
        
    $page $_GET['page'] . '.txt';
      } else {
        
    $page 'home.txt';
      }

    // Check to see if file exists and include it in.
      
    if (file_exists("pages/$page")) {
        include(
    "pages/$page");

    // If page doesn't exist, give an error message.
      
    } else {
        echo(
    "<h1 align=\"center\">Page cannot be found</h1>\n");
      }
    Also scythe: I could never get that menu switching to work after many tries :/
     
  18. scythe

    scythe Member

    Joined:
    Aug 15, 2002
    Messages:
    179
    Location:
    Brisbane
    You should be able to fix the undefined index problem by adding an isset() to your if statement:

    PHP:
    // Set $page to "home.txt" if a parameter isn't passed
      
    if (isset($_GET['page'])) {
        
    $page $_GET['page'] . '.txt';
      } else {
        
    $page 'home.txt';
      }

    // Check to see if file exists and include it in.
      
    if (file_exists("pages/$page")) {
        include(
    "pages/$page");

    // If page doesn't exist, give an error message.
      
    } else {
        echo(
    "<h1 align=\"center\">Page cannot be found</h1>\n");
      }
    The problem that you may have with using the dynamic way is that you are at risk of someone being able to view any .txt file on the server. This may or may not be a problem for you, but it's worth noting. You could make it a little better by adding a quick check on the $page variable (that it only contains letters, numbers, hyphens or underscores)

    PHP:
    // Set $page to "home.txt" if a parameter isn't passed
      
    if (isset($_GET['page'])) {
        
    $page $_GET['page'] . '.txt';
      } else {
        
    $page 'home.txt';
      }

    // Check to see if page name contains only letters, numbers, - or _ and that the file exists.
      
    if (preg_match("#^[a-z0-9_]+$#i",$page) && file_exists("pages/$page")) {
        include(
    "pages/$page");

    // If page doesn't exist, give an error message.
      
    } else {
        echo(
    "<h1 align=\"center\">Page cannot be found</h1>\n");
      }
    As for the menu thing, I did a little bit more research and the following should work:

    PHP:
    <div id="menu"> 
    <?php  
    $page 
    = (isset($_GET['page']) ? $_GET['page'] : '');
    $_GET = array();
    $_GET['page'] = $page;
    include(
    'template/menu.php');
    ?> 
    </div>
     
    Last edited: Sep 13, 2009
  19. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,244
    Location:
    Armadale / Perth
    Will have a look soon.

    Update Just looked the code below doesn't work stright no page is loaded with this, Ill do some slight google:
    PHP:
    preg_match("#^[a-z0-9_]+$#i",$page) &&
    I'm a idiot scythe the fricking menu code was working all along just needed the php tags on the the menu file :/

    I kinda realized I had to put a issest but with it that simple I feel ashamed, as I did something similar earlier on the switch.

    Kinda aware of the risk I was thinking of using htm instead of .txt as that guy had saw you had code there but page came up blank with it.

    [Kinda rant to get things of my chest and frustrations follows]

    Also I'm really half regretting the decision to use all div and no tables as some things are bloody complex to do.

    Was trying to get a autosize block that autosized in all directions both height and width, but fell totally flat on my face as you cant do a 9 div in 3 row block like you can in a table. May end up just having a 3 row div that expands automatically vertically instead of expend width wise.

    Also I cant get my head around a header design I want something like the wordpress one and others you see around but variable width and I'm soo lacking creativity to think of a good design.

    Also I've put in dreamweaver that I may look at using also for some things as at the moment I'm doing it all in Notepad++

    The site is starting to come along slowly.

    I never thought from a simple 3 div template I was originally wanting I would end up creating a kinda blog style look.

    [/rant]
     
    Last edited: Sep 13, 2009
  20. scythe

    scythe Member

    Joined:
    Aug 15, 2002
    Messages:
    179
    Location:
    Brisbane
    Sorry, change the #s to /s and it should work.

    Alsol, for layouts, try looking around somewhere like http://layouts.ironmyers.com/ or just do a google search for CSS Layouts.

    Stick with DIVs rather than tables. If you really get stuck, you can always make the DIVs behave like tables.
     

Share This Page

Advertisement: