Results 1 to 3 of 3

Thread: [RESOLVED] include files to index

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [RESOLVED] include files to index

    how can i include files to the index site using a menu to navigate with ?q= ??? i'm not sure what this is called but i'm sure someone will know what i mean...

    like if you type the link of the site or just index.php?q=users then it will replace the content of my site with the contents of users.php

    sorry i can't explain this very well as i don't know exactly what it is...

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: include files to index

    something that works generally like this:
    PHP Code:
    <?php

      $path 
    "./"//path to include directory
      
    $extension ".inc.php"//I'd use .inc.php rather than just .php to be somewhat more secure

      /** get the action **/
      //using long if statements, I usually use ternary operators instead
      
    if(isset($_GET['a'])){
        if(
    file_exists($path $_GET['a'] . $extension)){
          
    //action does exist
          
    $action $_GET['a'];
        }else{
          
    //they tried an action that doesn't exist
          
    $action "error";
        }
      }
      
    //if the action wasn't set, set a default
      
    if(!isset($action)){
        
    $action "main";
      }

      
    //we're done our "action logic", so spit out our page 'template'
    ?>
    <html>
      <head>
        <title>My page</title>
      </head>
      <body>
        <ul id="menu">
          <li><a href="?a=main">Home</a></li>
          <li><a href="?a=contact">Contact</a></li>
          <li>...</li>
        </ul>
        <div id="content">
    <?php
      
    //we are now at the point where we can include our action file
      
    require_once($path $action $extension);
    ?>
        </div>
      </body>
    </html>
    that's pretty much it. ask questions if you're confused or need help.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: include files to index

    this is exactly what i needed, thank you.

Posting Permissions

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



Click Here to Expand Forum to Full Width