server query to eliminate ?id= from a dynamic inclusion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
onesweetmoment
Forum Newbie
Posts: 2
Joined: Fri May 14, 2004 8:34 pm

server query to eliminate ?id= from a dynamic inclusion

Post by onesweetmoment »

Hi,

I have recently updated all my dynamic inclusion files to:

Code: Select all

<?php 

if($_GET['band']) 
{
$id = $_GET['band']; 
include("bands/" . $id . '.php'); 
}
else 
{
include("bands/band_index.php");
}

?>
I was just curious as to whether it would be possible to eliminate the "band=" i.e bands.php?nirvana instead of bands.php?band=nirvana...

Any help gratefully appreaciated..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

something like this?

Code: Select all

if(!empty($_GET))
{
  foreach($_GET as $k => $v)
  {
    if(preg_match("/^[a-z0-9_]+$/i",$k) && is_file("bands/$k.php"))
    {
      include("bands/$k.php");
      break;
    }
  }
}
else
{
  include("bands/band_index.php");
}
onesweetmoment
Forum Newbie
Posts: 2
Joined: Fri May 14, 2004 8:34 pm

Post by onesweetmoment »

Yeah that works perfectly! Thanks so much! :D
Post Reply