...

View Full Version : PHP include problem



dethzilla
08-08-2008, 09:06 AM
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.

abduraooft
08-08-2008, 09:30 AM
See http://php.net/manual/en/reserved.variables.get.php, http://php.net/manual/en/reserved.variables.post.php, http://www.tizag.com/phpT/postget.php

dethzilla
08-08-2008, 10:08 AM
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")?

Iszak
08-08-2008, 10:24 AM
Well in the main.php page you might have.



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.

dethzilla
08-08-2008, 10:35 AM
Perfect, that is exactly what I was going for, Iszak. Thanks much.

hinch
08-08-2008, 11:23 AM
or use a switch instead of long winded if's

this is from something i'm working on atm



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";
};
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum