[thelist] Dynamic Title / Meta

Benjamin Hawkes-Lewis bhawkeslewis at googlemail.com
Mon Jul 26 01:50:30 CDT 2010

On Sun, Jul 25, 2010 at 3:41 AM, DAVOUD TOHIDY <dtohidy at hotmail.com> wrote:
> I am trying to have different titles, etc. for different pages. The index.php is the main page where other pages are being dynamically placed and replaced within this page by defining an array and etc.
> $mypage = array ("" => "myhomepage.php", "0x01" => "mycontactpage.php",   // etc.
> );
> I have the following in the header of index.php file:
> switch($_SERVER['PHP_SELF'])
> {
> case '/index.php':
>     $title = 'Home page title';
>     $keywords = 'DeltaReprographics, Quality and etc.';
>     $description = 'DeltaReprographics is a quality printer solution provider';
>     break;
> case '/?pId=0x01':
>     $title = 'Company Overview';
>     $keywords = 'overview, overview2';
>     $description = 'This is the overview of the DeltaReprographics';
>     break;
> default: '/index.php';
> }
> It only shows the title etc. for index.php page. Other pages do not have their own title. etc.

$_SERVER['PHP_SELF'] is defined as follows:

"The filename of the currently executing script, relative to the
document root. For instance, $_SERVER['PHP_SELF'] in a script at the
address http://example.com/test.php/foo.bar would be
/test.php/foo.bar. The __FILE__ constant contains the full path and
filename of the current (i.e. included) file"


Since you are dynamically constructing the URLs using "index.php", the
filename of the currently executing script is "index.php" no matter
which URL you request, so $title will always be set to "Home page

I suspect you want $_SERVER[''REQUEST_URI'].

Benjamin Hawkes-Lewis

More information about the thelist mailing list