Re: ?=something
| From: | Matt McClanahan | Date: | Wed, 17 Oct 2001 16:46:25 +0000 |
| Subject: | Re: ?=something | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71356@lists.php.net to get a copy of this message | ||
On Wed, Oct 17, 2001 at 03:07:43AM -0400, Kacey A. Murphy wrote:
> I have noticed some sites have a great way of putting there links to urls, I
> always just put the normal link such as url=products.php is there a way to
> make a list of all the urls and direct them to like say they click on
> DOWNLOADS the url that will show on the url screen would be
> http://myweb.com/=?downloads but it is really going to
> http://myweb.com/downloads.php
>
> does that make sense??? I hope. Thanks
http://myweb.com/=?downloads would require some web
server settings
to force '=' to be a file parsed by PHP. As an alternative,
http://myweb.com/?downloads is easy to do with PHP on its
own, since
'downloads' will be the query string.
How you process the query string can vary depending on how many pages you're
going to be redirecting to, and how the page should behave. For
example, if all the redirections will do the same thing (Put up a
header/sidebar and include a template, for example) then you just need
to make sure $QUERY_STRING is a valid page.
<? // index.php
include 'header.php';
include 'sidebar.php';
$valid_pages =
Array('downloads','home','news','contact','support');
if (in_array($QUERY_STRING,$valid_pages))
include "$QUERY_STING.php";
else
include 'home.php'; // Default to the main page
?>
However if you want to run different code depending on the page, it may
be better to use a switch loop or some other method. A switch loop
would look something like this.
<? // index.php
include 'header.php';
include 'sidebar.php';
switch ($QUERY_STRING)
{
case 'news':
// code for news
break;
case 'downloads':
// code for downloads
break;
// .. and so on
case 'home':
default:
// code for home (the default)
}
?>
Incidentally, you can do a similar trick with any file by using
$PATH_INFO. For example, http://myweb.com/browse.php/5
has a
$PATH_INFO of '/5'. Strip off the slash, and 5 may refer to a category
to browse in, which may look cleaner than 'browse.php?id=5'.
Matt