treehouse : what would you like to learn today?
Web Design Web Development iOS Development

PHP Page Titles

  • I'm sure this is a novice problem but I can't figure it out..

    I currently used one php file (index2.php) to call the content into the body of the layout using this php include

    <?php 
    if (isset($_GET['id'])) {
    if (file_exists($_GET['id'] . '.txt')) {
    include $_GET['id'] . '.txt';
    }
    }
    ?>


    my question is that within the content how do I give those pages (about us, testimonials, tax services, etc.) there own titles instead of it defaulting to the index2.php title? I'm trying to be SEO friendly and I know having the same title on every page isn't going to help my cause. Thanks in advance for your assistance.
  • Set a body id. Then depending on that id write an if-statement echoing the title.
  • Not to sound dumb but how would I do that?
  • I'm still learning, but a simple way I'm using at the moment is using $_GET method from the page url and the page link clicked:


    <html>
    <head>
    <?php
    if ($_GET ['content'] == 'home'){
    echo ('<title>Website :: Home</title>');
    }
    else if ($_GET ['content'] == 'contact'){
    echo ('<title>Website :: Contact</title>');
    }
    ?>
    </head>
    <body>
    <a href="window.location.href='index.php?content=home">Home</a><br />
    <a href="window.location.href='index.php?content=contact">Contact</a>
    </body>
    </html>
  • It works, greatly appreciated!
  • I hope you learn from it. You're welcome.