PDA

View Full Version : Page Title



unified
08-19-2006, 07:12 AM
Can anyone tell me how to dynamically set a page's title so that it appears in the title bar of the browser? I want to be able to pass a variable ($author) from one page and make it the title of the receiving page. I have searched for 3 hours and have failed to find anything.

I've tried : <title><?php $author ?></title> , but this does not work. I pass it something like http://www.mysite.com/mypage.php?author=John%20Doe but it only displays the url in the title bar in IE, and nothing at all in NS and FF.

Thanks.

shachi
08-19-2006, 08:02 AM
try <title><?php $_GET['author'] ?></title>

And anyways PHP is not a browser dependant language if it works in one browser so does it in all.

DimX
08-19-2006, 08:07 AM
Shouldn't there be echo before the variable???

<title><?php echo $_GET["author"] ?></title>

shachi
08-19-2006, 08:10 AM
Oh yes, there must be an echo. Thanks for pointing that out DimX.:)

unified
08-19-2006, 08:18 AM
Had to change my post as I did not see DimX's post with change. It worked perfectly. :)

Thanks to you both.

DimX
08-19-2006, 08:20 AM
It works fine: http://www.unified-dsa.com/test4.php?author=John%20Doe
Or if you have a variable called $author then you must replace $_GET["author"] with $author

unified
08-19-2006, 08:27 AM
I actually had that before, I think: <title><?php echo $author ?></title> and it did not work, <title><?php echo $_GET["author"] ?></title> does work.

DimX
08-19-2006, 08:31 AM
You probably have a BUG in your php code, make sure that $author has a value and is not an empty string.

unified
08-19-2006, 08:47 AM
Yep. $author didn't was an empty string. :p

Thanks again for all your help.

djr33
08-21-2006, 07:50 AM
If "register globals" is turned on (a php setup thing), then there's no need to use the GET variables, but it seems it's not on.
Anyway, that works.

Also, I'll just point out that you should have a semicolon in that.

<?php echo $_GET['author']; ?>

If you wanted to add more after that, you'd need the semi-colon. It's not crucial in the "simple php syntax", or whatever that's called, but it's a good habit nonetheless.

Twey
08-21-2006, 03:46 PM
If "register globals" is turned on (a php setup thing), then there's no need to use the GET variablesIf "register globals" is turned on, it's time to turn it off. :)