Getting the Header to display different page titles

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
alex.saidani
Forum Newbie
Posts: 7
Joined: Mon Jan 25, 2010 2:15 pm

Getting the Header to display different page titles

Post by alex.saidani »

I have written a script for my website's header that is completely seperate to all the pages, this was to make it easier for me to edit the header, rather than going into every page. However the problem is i can only get this script to dispaly one title for every single page. I was just wondering if anyone could offer any help on how to get the header to display a different title for each page.
Thanks in advance :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Getting the Header to display different page titles

Post by pickle »

A couple ways:

1) In your header script, you could figure out the filename of the current page (something like: basename($_SERVER['REQUEST_URI']) could work). Then display a particular title depending on the filename

2) A more flexible way would be to include the title of the page in the file that is including the header script:

Code: Select all

<?PHP
$title = "This is my blog";
include "header.inc";
 
... rest of the page
?>
Then have your header.inc file work with $title.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
alex.saidani
Forum Newbie
Posts: 7
Joined: Mon Jan 25, 2010 2:15 pm

Re: Getting the Header to display different page titles

Post by alex.saidani »

Thanks for the help, i intended to put the title part inside the header.
This is what i tried, did not work though, i clearly am doing something wrong :/

Code: Select all

 
<title>
<?php 
$title= basename($_SERVER['REQUEST_URL'])
if ($title == "index.php") {
   echo "Moovie :: Home"; 
   } 
?>   
</title>
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Getting the Header to display different page titles

Post by pickle »

It's REQUEST_URI (you-are-eye) not URL (you-are-ell)

Please use [syntax=php][/syntax] tags when posting PHP code.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply