1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Links in PHP inc

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

  1. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    edit:: ga mist your last post it should be strip_tags() not striptags().

    Ok
    For this to work you need to put all the files that contain the contents in a folder called 'content' (with out the ''). The path to this folder needs to be put in this include (its from the main block VV) so php knows were to look for the files, or you just end up with a php call error thing.
    PHP:
            <div id="content"><?php

                             
    include_once('content/'.$page);

                              
    ?></div> 
    Then the name of the file needs to be added to the array along with the name that you want to have linking to it.

    eg::
    if you have a file called reviews.php and you want it to be the file thats included, when you have a link to
    <a href="index.php?page=reviews" >Reviews</a>
    then add VV to the array (the last one in the array should not have ',' at the end)
    'reviews' => 'reviews.php',
    so
    PHP:
    $pages = array(
        
    'home' => 'index.php',
        
    'news' => 'news.php',
        
    'blog' => 'blog.php',
        
    'contact' => 'contact.php',
        
    'forums' => 'forums.php',
        
    'reviews' => 'reviews.php'
    );
    since you don't need some in the array you can remove them.
    main::
    PHP:
    <?php
    $pages 
    = array(
        
    'home' => 'index.php',
        
    'news' => 'news.php',
        
    'contact' => 'contact.php',
        
    'forums' => 'forums.php',
        
    'reviews' => 'reviews.php'
    );

    if(!
    $_GET['page']) {$page $pages[home];}
    else {
    $page $pages[$_GET['page']];
    if(empty(
    $page)) $page 'error.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_once('content/'.$page);

                              
    ?></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>
    any errors that you get with running this bit of code, post them and we can see whats going wrong.
     
    Last edited: 18 Apr 2005
  2. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    here you go:

     
  3. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    ok there is no folder in you 'public_html' called 'content' or the 'content' folder dose not have a file in it called 'reviews.php' :)

    edit:: I'm tired so I'm going to bed, got to be up early tomorrow.
     
    Last edited: 18 Apr 2005
  4. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    i think i get it now, so i make one folder to put all the main pages and other folders to drag files from that are used on the main pages

    e.g. main files: content
    other files: reviews
    forum
    etc
     
  5. FuzzyOne

    FuzzyOne

    Joined:
    19 Sep 2002
    Posts:
    1,839
    Likes Received:
    37
    for the hell of it ...

    PHP:
        <?php

        
    if (!isset($HTTP_GET_VARS['act'])) {
            @include(
    "includes/somedefaultpage.inc.php");
        } else {
            
    $path 'includes/';
            
    $extension '.inc.php';
            
            if ( 
    preg_match("#^[a-z0-9_]+$#i",$HTTP_GET_VARS['act']) ){
                
    $filename $path.$HTTP_GET_VARS['act'].$extension;
                if (
    file_exists($filename)) {
                    @include(
    $filename);
                } else {
                    include(
    "includes/somedefaultpage.inc.php");
                }
            }
        }
        
        
    ?>
    then call it via ?act=somepage
     
  6. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    yep.
    if the site get's big then i would start using a database for your contents.

    erm looks like there are lots of ways to do this and any here should work, just depends on witch one you find the easiest to use.

    FuzzyOne's:
    dose not need you to add a list of files to the array.
    can only have all the main files in one folder.

    Mine:
    can have files in sub folders to the content folder.
    needs array.
     
    Last edited: 19 Apr 2005
  7. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    i got your way working, so i'll stick with that and recode it if it gets to big like you said :)

    thanks for the help :)
     
  8. cfuk

    cfuk What's a Dremel?

    Joined:
    9 Jul 2004
    Posts:
    711
    Likes Received:
    0
    one last thing how do i code a login block from my home page to phpbb forum?
     
  9. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    This would do for logging in and will take you to the forum, but if you want it to tell you if your logged in then that would take a bit more thought.

    Code:
    <form action="/forum/login.php" method="post" name="loginForm" >
    Username ::
    <br />
    <input type="text" class="post" name="username" size="12" maxlength="12" value="" />
    <br />
    Password ::
    <br />
    <input type="password" class="post" name="password" size="12" maxlength="12" /><input type="hidden" name="redirect" value="" />
    <br />
    <input type="submit" name="login" class="mainoption" value="Log in" />
    </form>
    you need to change ::
    <form action="/forum/login.php" method="post" name="loginForm" >
    to link to the login.php file in your phpbb setup.
     

Share This Page