Page titles in php docs

Discussion in 'PHP' started by canalboatman, Jun 29, 2010.

  1. #1
    Help!

    Back in late 2007 I was very kindly helped to sort out a problem on my website.

    I have a header document in an "includes" folder which is attached to each pagfe on my site using php.

    In order to get a different description for each page, I was using the following code:

    <title><?php echo $page_title; ?></title>
    <?php
    if(!isset($meta)) {
    $meta = "Default Meta Description";
    }

    ?>
    HTML CODE
    <meta name="description" content="<?php echo $meta;?>" />'
    REST OF HTML CODE

    This is all that goes into header.php. So say you have page1.php
    <?php
    $page_title = 'Canal boats, narrowboats, tugs and Dutch barges for sale';
    $meta = "This is all about page1";
    include "header.php";

    ?>

    Now it is not working and I get a parsing error caused by one of the ? in the <title><?php echo $page_title; ?></title> line of code.

    Where have I gone wrong? If you look at my site at the moment each page is currently untitled because of this. I can go back to just one title in the header.html doc, but don't want to for obvious reasons.

    Any guidance much appreciated.
     
    Last edited: Jun 29, 2010
    canalboatman, Jun 29, 2010 IP
  2. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You said your header was placed in an "includes" folder so this:

    include "header.php";
    PHP:
    should actually be:

    include "includes/header.php";
    PHP:
     
    Michellu, Jun 29, 2010 IP
  3. canalboatman

    canalboatman Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Indeed. I have typed that in to this post incorrectly and it is correct on the actual pages. It has to be, otherwise if you went to my site the header would be missing, which it isn't.

    The problem exists in the PHP code placed in the header document, but it used to work, which is why I am flummoxed by it.
     
    canalboatman, Jun 29, 2010 IP
  4. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If your code used to work and it suddenly stopped maybe you have made changes to the PHP settings or Apache settings or upgraded either to a newer version.
    For example maybe you used short tags in your code <? ?> instead of <?php ?> and recently you altered the php.ini to set short_open_tag = Off (say by upgrading PHP ).
    Or maybe you made some recent changes to your code and forgot to close a php tag.
    Think what did you changed just before this error occurred.
    Also show us the exact error your getting, maybe we can get an additional hint from there.
     
    Michellu, Jun 29, 2010 IP
  5. canalboatman

    canalboatman Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the input Michellu. I've fixed it now. There was a simple error in the code. One of those where you stare at it and think, well, there's nothing wrong with that, and suddenly you notice the glitch. Drove me mad for half a day though :)
     
    canalboatman, Jun 30, 2010 IP