note 47221 deleted from reserved.variables by aidan
| From: | aidan@php.net | Date: | Sun, 07 Nov 2004 06:32:33 +0000 |
| Subject: | note 47221 deleted from reserved.variables by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80211@lists.php.net to get a copy of this message | ||
Note Submitter: justin dot shreve at gmail dot com
----
I need a way to load a page depending on the $_GET value entered (or $HTTP_GET_VARS depending on
your version or coding standard.)
So, I could use longer urls like so:
a=feeds&feed=rss
or I could do something like:
feed=rss
But how? I can't load it without knowing the query string value being feed (?feed=).
So I just came up with:
<?php
$get = explode("?", $_SERVER['QUERY_STRING'],1);
$get = $get[0];
$query_string = explode("=", $get, 2);
$query_string = $query_string[0];
?>
and $query_string would be id (if you entered id=something)
Therefor I could do:
<?php
$pages = array(
'profile' => "profile",
'comment' => "comment",
'trackback' => "trackback",
'archives' => "archives",
'category' => "category",
'options' => "options",
'feeds' => "feeds",
'index' => "main",
'search' => "search",
'calendar' => "calendar",
);
if (empty($pages[$query_string]) )
{
$_GET[$query_string] = 'index';
$pages[$query_string] = "main";
}
/* After the check
Require the source file and display */
require_once (home."includes/pages/".$pages[$query_string].".php");
$load = new $pages[$_GET[$query_string]];
?>
(I have home set as ./:
<?php define("home", "./"); ?>