Page 1 of 1

require_once - form variable

Posted: Sun May 25, 2008 11:33 am
by omnigate
WHAT:
I would like to know if I can pass a form variable (or something similar) using require_once function:
ie. require_once nav.php?select=$sid

WHY:
I'm building a master page that uses several require_once statements to pull in the different areas of my site. One of those require_once statements calls a navigation page (nav.php). But I want to tell the nav.php page to load certain data based on a URL parameter.

Basically, that nav.php file is connected to a single table within a database. That table contains all the menu items (and sub-menu items) of my site. I didn't want to have to setup a separate nav.php for every section of the site, so I was trying to re-use the nav.php page using variables. In that particular table, there is a sid column. This would be populated with (VARCHAR) the menu item ie. calendar, instruction, main, etc. Then, I would pass this to my master page using a URL parameter:
ie. master.php?body=calendar.php&sid=calendar

Then in my master page. I would take the sid parameter and pass it to the nav.php require_once command:
$sid = $_GET['sid'];
require_once nav.php?select=$sid

When the detail page recieves this information, it would take the variable and place it into the SQL query.
$select = $_GET['select']
SELECT * FROM menu WHERE sid=$select

Then when it calls my nav.php bar in to display the available menu options (after someone clicked CALENDARS for example), it would pull only those database items that matched 'calendar' and display the long list of calendar items. Same if they clicked instruction button, it would populate the nav.php bar in the main page with only those instruction menu items.

I suppose I could place the logic directly into the master page, however, I really like keeping things segregated for administration, organization and sometimes security.

Maybe I'm going about this the wrong way, but thought I would give this path a try. I can't find anything in the documentation that allows or disallows this process.

Thanks.

Re: require_once - form variable

Posted: Sun May 25, 2008 11:40 am
by LSJason
That would be HORRIBLY insecure...