I am coding a website in php for a school project and have hit a stump.
My pages are loaded with dynamic variables in the url
ie. http://example.com/index.php?page=home
ie. http://example.com/media.php?page=pics&pic=01
etc..
In all these files (index.php , media.php etc) i have one global header which specifys all the head tags and opens the html and body tags. In the content i only now have to add the actual content. This worked fine as i would just specify the page title as a variable before the header file is processed.
i.e <title> <?php ($page_title); ?> </title>
$page_title = "Home Page";
But after i started to add arguments into the url which would fetch different pages,
all those different pages ie ?page=pics ?page=videos etc
the title would be the one specified by the page ie /media.php
To solve this problem i wrote this set of code and was wondering if it would work?
if $_SERVER['REQUEST_URI'] == ("media.php?page=vids")
{
$sub_title = "Videos";
}
else if $_SERVER['REQUEST_URI'] == ("/media.php?page=pics")
{
$sub_title = "Pictures";
}
else if $_SERVER['REQUEST_URI'] == ("/media.php?page=gifs")
{
$sub_title = "Animated GIFS";
}
I am pretty sure that this would work, so please leave comments.
Also could i add a wildcard such as:
if $_SERVER['REQUEST_URI'] == ("/media.php?page=vids"*)
{
$sub_title = "Videos";
}
so if someone went to the page: /media.php?page=vids&vid=01
it would have the same title as : /media.php?page=vids
This is just so i don't have to add a record for each single combination of variables.
Thanks in advance.