Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Page Title

  1. #1
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Page Title

    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.

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  3. #3
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Shouldn't there be echo before the variable???
    Code:
    <title><?php echo $_GET["author"] ?></title>

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh yes, there must be an echo. Thanks for pointing that out DimX.

  5. #5
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Had to change my post as I did not see DimX's post with change. It worked perfectly.

    Thanks to you both.

  6. #6
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    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

  7. #7
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  8. #8
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    You probably have a BUG in your php code, make sure that $author has a value and is not an empty string.

  9. #9
    Join Date
    Aug 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yep. $author didn't was an empty string.

    Thanks again for all your help.

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •