Trying to change page titles with PHP

Hello, I’m trying to change the page titles on a site I’m working on using PHP but I’m not sure how to do it. Each page comes from the index.php page so the page URL’s all look something like this:

/index.php?page=about
/index.php?page=contact

I have found some code that seems like it’s close but it’s only using the “Transportation Insurance” title and applying that to all of the pages:

[php]

<?php $title; $path=$_SERVER['PHP_SELF']; $page=basename($path); switch("$page") { case 'index.php': $title = 'Transportation Insurance'; break; case 'index.php?page=home': $title = 'Transportation Insurance'; break; case 'index.php?page=newsletter': $title = 'Newsletter'; break; case 'index.php?page=privacy': $title = 'Privacy Policy'; break; case 'index.php?page=links': $title = 'Links'; break; case 'index.php?page=contact': $title = 'Contact Us'; break; case 'index.php?page=about': $title = 'About Us'; break; case 'index.php?page=quote': $title = 'Request A Quote'; break; case 'index.php?page=terms': $title = 'Terms of Use'; break; } echo ''.$title.''; ?>

[/php]

I appreciate any help.

Here you go

[php]<?php

$page = !empty($_GET[‘page’]) ? $_GET[‘page’] : ‘home’;
switch ($page) {
case ‘home’:
$title = ‘Transportation Insurance’;
break;
case ‘newsletter’:
$title = ‘Newsletter’;
break;
case ‘privacy’:
$title = ‘Privacy Policy’;
break;
case ‘links’:
$title = ‘Links’;
break;
case ‘contact’:
$title = ‘Contact Us’;
break;
case ‘about’:
$title = ‘About Us’;
break;
case ‘quote’:
$title = ‘Request A Quote’;
break;
case ‘terms’:
$title = ‘Terms of Use’;
break;
default:
$title = 404;
break;
}

?>

<?= $title ?> [/php]

Awesome! That worked perfectly.

Thank you very much! I appreciate your help.

Sponsor our Newsletter | Privacy Policy | Terms of Service