Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy PHP include problem

    Hello, I'm very new to the PHP game. I've tried searching various PHP resource sites and I still have one pressing question I need answered in order to get my site off the ground.

    I often see sites with things such as "main.php?id=section" in their URL. I have yet to find any tutorial on how to set up a variable include like that.

    Any help would be much appreciated. Thanks.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    dethzilla (08-08-2008)

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you for the quick reply, abduraooft, but I'm afraid I'm still missing something. After reading through the links you provided, I don't yet quite understand how I do what I'm trying to do.

    To elaborate, I've got my site laid out in HTML already. I've got a navigation bar to the side and I want to use PHP to call up content into the content area. How can I set the links to determine what gets displayed in said content area (this is asked in reference to the concept of "main.php?id=content")?

  • #4
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Well in the main.php page you might have.

    PHP Code:
    if (isset($_GET['id']))
    {
      if (
    file_exists("./pages/{$_GET['id']}.php"))
      {
        include 
    "./pages/{$_GET['id']}.php";
      }

      else
      {
        include 
    "./pages/404.php";
      }
    }

    else
    {
      include 
    "./pages/home.php";

    and then you'll store all your files in a folder called "content" and then when someone goes to main.php?id=content it'll check if the id is set if so check if file exists if it doesn't get a 404 (file doesn't exist) page that you'll create and if it is pull the page. As for no id is set (assuming someone game directly to main.php) get home page.

  • Users who have thanked Iszak for this post:

    dethzilla (08-08-2008)

  • #5
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Perfect, that is exactly what I was going for, Iszak. Thanks much.

  • #6
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    or use a switch instead of long winded if's

    this is from something i'm working on atm

    PHP Code:
    if (!isset($_GET['LoadModule'])) {
        include 
    "modules/home.php";
    } else {
    switch (
    $_GET['LoadModule']) {
        case 
    "home":
             include 
    "modules/home.php";
        break;
        case 
    "admin":
             include 
    "modules/admin.php";
        break;
        case 
    "Users":
             include 
    "modules/users.php";
        break;
        case 
    "Settings":
             include 
    "modules/settings.php";
        break;
        case 
    "ACLRoles":
             include 
    "modules/aclroles.php";
        break;
        case 
    "leads":
             include 
    "modules/leads.php";
        break;
        case 
    "noteviewer":
             include 
    "modules/noteviewer.php";
        break;
        case 
    "admin-leadsource":
             include 
    "modules/admin-leadsource.php";
        break;
        case 
    "admin-leadstatus":
             include 
    "modules/admin-leadstatus.php";
        break;
        case 
    "admin-leadsubstatus":
             include 
    "modules/admin-leadsubstatus.php";
        break;
        case 
    "quicksearch":
             include 
    "modules/quicksearch.php";
        break;
        case 
    "notes":
             include 
    "modules/notearchive.php";
        break;
        case 
    "office":
             include 
    "modules/officeadmin.php";
        break;
        case 
    "notifications":
             include 
    "modules/notifications.php";
        break;
        case 
    "Calls":
             include 
    "modules/mycalls.php";
        break;
        case 
    "reports":
             include 
    "modules/reports.php";
        break;
        default:
             include 
    "modules/error.php";
        };

    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com


  •  

    Posting Permissions

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