How would I dynamically change Meta Tag Information?

Hi Everyone,

How would I dynamically change meta tag information on a per page basis?

If a visit is on my “about” or “inventory” page. In the title and meta tag I would want that user to see “about us” or “inventory”. How would I do something like that? Thanks!

For example, this page should be echoing out “Title Test Page” but it’s not. What am I doing wrong here?
Thanks!

http://whatsmyowncarworth.com/class-work/sign3/titletest.php

<?php
$title;
switch($_SERVER['PHP_SELF'])
{
case '/index.php':
$title = 'Home';
break;
case '/titletest.php':
$title = 'Title Test Page';
break;

}

echo '<title>'.$title.'</title>';
?>

Have you checked what $_SERVER[‘PHP_SELF’] is returning?

You do not have a default option which may also give you any indications of a problem.

I use:


$path_parts = pathinfo($_SERVER['PHP_SELF']);
$filename = basename($path_parts['basename']);
.
.
.
switch ($filename) {
case "index.php":
$metaDesc = "Blah blah blah";
$metaKey = "Photos";
break;
case "contact.php":
.
.
.

I do not like this way of doing things as it is not as easy to find errors:

switch($_SERVER['PHP_SELF'])  

Hey Rubble,

Thanks for your response but I actually just figured it out.

This is what I think what is happening.
The request_uri acts as a unique identifier of the page and whatever URL the user is on, the page echos out the $title variable? Is that correct?

Thanks!

$title;
$url = $_SERVER['REQUEST_URI'];
switch($url){

 case "/class-work/sign3/titletest.php";
 $title = 'Title Test Page!';
 break;

etc.....
 }