Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-08-2008, 09:06 AM   PM User | #1
dethzilla
New to the CF scene

 
Join Date: Aug 2008
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
dethzilla is an unknown quantity at this point
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.
dethzilla is offline   Reply With Quote
Old 08-08-2008, 09:30 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
dethzilla (08-08-2008)
Old 08-08-2008, 10:08 AM   PM User | #3
dethzilla
New to the CF scene

 
Join Date: Aug 2008
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
dethzilla is an unknown quantity at this point
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")?
dethzilla is offline   Reply With Quote
Old 08-08-2008, 10:24 AM   PM User | #4
Iszak
Regular Coder

 
Iszak's Avatar
 
Join Date: Jun 2007
Location: Perth, Western Australia
Posts: 332
Thanks: 2
Thanked 58 Times in 57 Posts
Iszak is an unknown quantity at this point
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.
Iszak is offline   Reply With Quote
Users who have thanked Iszak for this post:
dethzilla (08-08-2008)
Old 08-08-2008, 10:35 AM   PM User | #5
dethzilla
New to the CF scene

 
Join Date: Aug 2008
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
dethzilla is an unknown quantity at this point
Perfect, that is exactly what I was going for, Iszak. Thanks much.
dethzilla is offline   Reply With Quote
Old 08-08-2008, 11:23 AM   PM User | #6
hinch
Regular Coder

 
hinch's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 921
Thanks: 25
Thanked 79 Times in 79 Posts
hinch is on a distinguished road
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
hinch is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:28 PM.


Advertisement
Log in to turn off these ads.