Development Links in PHP inc

Discussion in 'Software' started by cfuk, 17 Apr 2005.

  1. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    I'm making a new website with 5 PHP Incs and i was wondering if you click on a link is there away that only the middle include will change to speed up load time?

    Thanks :)
     
  2. nick[x1]

    nick[x1] What's a Dremel?

    Joined:
    1 Nov 2004
    Posts:
    242
    Likes Received:
    0
    Hi

    Are you talking about say a content site, and then only the center part changes with diffrent links?


    PS: Did i sell you a tank-o-matic :eyebrow:
     
  3. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    ya, but i don't want to use static frames if that's what you are going to say :p

    p.s. ya, sorry
     
  4. nick[x1]

    nick[x1] What's a Dremel?

    Joined:
    1 Nov 2004
    Posts:
    242
    Likes Received:
    0
    Ok, frames = bad :p

    This is a simple way
    So to link to home you would go to
    index.php?page=home

    To go to contact
    index.php?page=contact

    And so on

    Add this some where before you do the include in index.php

    PHP:
    <?
    $page striptags($_GET['page']);
    if (empty(
    $page)) { $page "home"; }
    if (
    $page == "home") { $toinc "content/home.php"; }
    elseif (
    $page == "contact") { $toinc "content/conact.php"; }
    elseif (
    $page == "etc") { $toinc "content/etc.php"; }
    else { 
    $toinc "content/link to a 404 error page.php"; }
    ?>
    Pretty basic :), might need something more on the striptags bit cant quite remember what you need off the top of my head

    Then say in your table inbetween the <td>'s or something

    PHP:
    <? 
    include 
    $toinc;
    ?>

    Should just about do it I hope :)
    The are other ways, i always have done it that way, if you have many files then its easier to use some other code
     
  5. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    i'm lost now :( here is my code:

    PHP:
     <html>
    <head>
    <link rel="stylesheet" type="text/css" href="style.css"/>
    <title>:: Half Review :: For all your computer needs</title></head>
    <body topmargin="0">
        <div id="container" topmargin="0">

            <div id="banner"><?php

                             
    include('banner.php');

                              
    ?></div>

            <div id="sidebar-a"><?php

                             
    include('left.php');

                              
    ?></div>

            <div id="sidebar-b"><?php

                             
    include('right.php');

                              
    ?></div>

            <div id="content"><?php

                             
    include('content.php');

                              
    ?></div>

            <div id="footer"><?php

                             
    include('footer.php');

                              
    ?>
            </div>
    </div>
    </body>
    </html>
     
  6. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    PHP:
    <?php
    $page 
    striptags($_GET['page']);
    if (empty(
    $page)) { $page "home"; }
    if (
    $page == "home") { $toinc "content/home.php"; }
    elseif (
    $page == "contact") { $toinc "content/conact.php"; }
    elseif (
    $page == "etc") { $toinc "content/etc.php"; }
    else { 
    $toinc "content/link to a 404 error page.php"; }
    ?>
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="style.css"/>
    <title>:: Half Review :: For all your computer needs</title></head>
    <body topmargin="0">
        <div id="container" topmargin="0">

            <div id="banner"><?php

                             
    include banner.php;

                              
    ?></div>

            <div id="sidebar-a"><?php

                             
    include left.php;

                              
    ?></div>

            <div id="sidebar-b"><?php

                             
    include right.php;

                              
    ?></div>

            <div id="content"><?php

                             
    include $toinc;

                              
    ?></div>

            <div id="footer"><?php

                             
    include footer.php;

                              
    ?>
            </div>
    </div>
    </body>
    </html> 
    edit:: don’t like all the elseif's would be tempted to put in some form of array/database if its a big site.
     
    Last edited: 17 Apr 2005
  7. Cookie Monster

    Cookie Monster Multimodder

    Joined:
    27 Aug 2003
    Posts:
    4,208
    Likes Received:
    388
    Ive just done links via an include, its discussed in my thread here not sure if it will help but it sorted me out.
     
  8. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    do i need to do any thing to

    PHP:
    <?php 

                             
    include('content.php'); 

                              
    ?></div>
    also do i just use the normal code for linking?
     
  9. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    yes see my post
     
  10. Hwulex

    Hwulex What's a Dremel?

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    Switches are your friend. ;) If you've got more than one else, you really should look at switching.

    PHP:
    switch ($_GET['page']) {
      case 
    'home':
        
    $toinc 'home.php';
        break;
      case 
    'contact':
        
    $toinc 'contact.php';
        break;
      default:
        
    $toinc 'index.php';
        break;
    # end switch

    include_once('content/'.$toinc);
    If you wanted, you could include a case for index and default to error.php, whatever you like. :)
     
  11. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    forgot about switches, I only used them a week ago :wallbash:.
     
    Last edited: 17 Apr 2005
  12. NoMercy

    NoMercy What's a Dremel?

    Joined:
    23 Nov 2004
    Posts:
    161
    Likes Received:
    0
    Any opinions on switch( $_GET['page'] ) { .. } vs $page = pages[ $_GET['page'] ] ?
     
  13. nick[x1]

    nick[x1] What's a Dremel?

    Joined:
    1 Nov 2004
    Posts:
    242
    Likes Received:
    0
    Some good replies there

    Mine was only a simple bit of code really for beginners

    PHP:
    <?php
    $page 
    $_GET['page'];
    $page "content/".$page.".php";
    if(isset(
    $page)){
        if(
    file_exists($page)){
            include(
    $page);
        }
        if(!
    file_exists($page)){
            include(
    'errors/404.php');
        }
    }
    if(!isset(
    $page)){
        include(
    'pages/home.php');
    ?>


    not the most secure code ever but its ok
     
  14. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    i would have gone with that, but Hwulex tends to be right so his way is probably quicker.

    PHP:
    <?php
    $pages 
    = array(
        
    'home' => 'index.php',
        
    'news' => 'news.php',
        
    'blog' => 'blog.php',
        
    'contact' => 'contact.php',
        
    'forums' => 'forums.php'
    ); 

    if(!
    $_GET['page']) {$page $pages[home];}
    else {
    $page $pages[$_GET['page']];
    if(empty(
    $page)) $page 'error.php';
    }
    include_once(
    'content/'.$page);
    ?>
    //now things are starting to get messy :blah:.
     
    Last edited: 18 Apr 2005
  15. NoMercy

    NoMercy What's a Dremel?

    Joined:
    23 Nov 2004
    Posts:
    161
    Likes Received:
    0
    Messy but you gain the ability to dynmaicaly generate your page list, which for some cases may be a bonus.
     
  16. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    missed that bit
    index.php?page=home //that would include the home page file.
    index.php?page=news //that would include the news page file.
    ......
    so
    <a href="index.php?page=home" >Home</a>
    <a href="index.php?page=news" >News</a>
    ......

    edit :: bare in mined that php on a Linux server is case sensitive.
    so Home is not the same as home.
     
    Last edited: 18 Apr 2005
  17. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    you have just all lost me :(. Is there a guide that will show me how to do it an easy way? Here is the code for the home page and the code for the left inc with the links

    PHP:
    <?php 
    $page 
    striptags($_GET['page']); 
    if (empty(
    $page)) { $page "home"; } 
    if (
    $page == "home") { $toinc "index.php"; } 
    elseif (
    $page == "contact") { $toinc "content/conact.php"; } 
    elseif (
    $page == "etc") { $toinc "content/etc.php"; } 
    else { 
    $toinc "content/link to a 404 error page.php"; } 
    ?> 
    <html> 
    <head> 
    <link rel="stylesheet" type="text/css" href="style.css"/> 
    <title>:: Half Review :: For all your computer needs</title></head> 
    <body topmargin="0"> 
        <div id="container" topmargin="0"> 

            <div id="banner"><?php 

                             
    include('banner.php'); 

                              
    ?></div> 

            <div id="sidebar-a"><?php 

                             
    include('left.php'); 

                              
    ?></div> 

            <div id="sidebar-b"><?php 

                             
    include('right.php'); 

                              
    ?></div> 

            <div id="content"><?php 

                             
    include("content.php"); 

                              
    ?></div> 

            <div id="footer"><?php 

                             
    include('footer.php'); 

                              
    ?> 
            </div> 
    </div> 
    </body> 
    </html> 
    left:
    PHP:
    <link href="style.css" rel="stylesheet" type="text/css">
    <
    div id "Navs">
    Navigations
    </div>
    <
    div id "table">
      - <
    a href="index.php" class="links">Home</a><br>
      - <
    a href="index.php?page=reviews" >Reviews</a><br>
      - 
    Articles<br>
      - 
    Guides<br>
      - 
    Contact Us<br>
      - 
    Forums<br>
    </
    div>
    <
    br>  
     <
    div id ="Navs">
      
    Downloads
     
    </div>
      <
    div id "table">
      - 
    Latest Downloads<br>
      - 
    Updates<br>
      - 
    utilis<br>
      - 
    Submit<br>
      </
    div>
    <
    br>
     <
    div id "Navs">
      
    Interactive
     
    </div>
     <
    div id "table">
      - 
    Readers Drives<br>
      - 
    PC Gallery<br>
      - 
    3D Mark Scores<br>
      - 
    Mods Shop<br>
     </
    div>
     
  18. nick[x1]

    nick[x1] What's a Dremel?

    Joined:
    1 Nov 2004
    Posts:
    242
    Likes Received:
    0
    Change

    <div id="content"><?php

    include("content.php");

    ?></div>


    to

    <div id="content"><?php

    include($toinc);

    ?></div>
     
  19. Hwulex

    Hwulex What's a Dremel?

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    Mine was more of a general programming pointer for all rather than a solution to the posted problem (shamefully). :blush:
     
  20. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    changed that coding but i've got this error

     

Share This Page