Results 1 to 4 of 4

Thread: PHP Title Tag With Includes Problem....

  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default PHP Title Tag With Includes Problem....

    Hey everyone, I have a problem with my page, I'm trying to SEO it, Here's what I did to begin with.

    I have an index.php where my content is, and I'm using this code to include .html pages into my main content page

    Code:
    <?
    
    $val = $_GET['id']; // Replace id with whatever you want to use, eg ?id=page
    
    $dirty = array("..");
    
    $clean = array("");
    
    $val = str_replace($dirty, $clean, $val); // Prevent people from viewing root files like your password (should work i just quikly added it without testing)
    
    
    if (isset($_GET['id'])) { // Replace id with whatever you want to use, eg ?id=page
    
    if (file_exists($val)) { // This checks if the file you are trying to call exists
    
    
    
    
    include "$val";
    
    }
    
    else {
    
    include "s71.html"; // If the file doesnt exists it calls your 404 error page
    
    }
    
    }
    
    else {
    
    include "s71.html"; // If ?id= is not set it will now go to your news page
    
    }
    
    ?>
    This allows me to basically link any page like http://www.divxnaruto.com/index.php?id=s71.html

    What I want to do is edit the <title> tag to change everytime I hit a different page, For example, s71.html I want the title to say "Naruto Shippuden 71 *DivX HD* Eng-Sub"

    I've been testing this method to solving the problem :

    Code:
    <?php if (defined ('TITLE')) {
                        print TITLE;
                    } else {
                        print 'Watch Naruto Episodes Online | Bleach Episodes | Manga';
                        }
            ?>
    and using this on the .html file :

    Code:
    <?php define ('TITLE', 'Page Title Here'); 
    ?>
    I'm a no0b, and I really need some help. Thanks guys.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Your on the right track. This should be in your HTML(well, it'd now be a PHP page. ) page:
    PHP Code:
    <?php
    $regTitle 
    "Page Title Here";
    define('TITLE',(isset($pTitle)) ? $pTitle $regTitle;
    echo 
    "<title>".TITLE."</title>";
    ?>
    Then in your code change:
    PHP Code:
    <?php if (defined ('TITLE')) {
                        print 
    TITLE;
                    } else {
                        print 
    'Watch Naruto Episodes Online | Bleach Episodes | Manga';
                        }
            
    ?>
    To this:
    PHP Code:
    <?php
    $pTitle 
    "Watch Naruto Episodes Online | Bleach Episodes | Manga";
    ?>
    Make sure that the above code(the one simply above this text), is included above the title of the page.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    desception (08-18-2008)

  4. #3
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Still having trouble getting it to work, I think also in this part of the code there was a missing ) *I have edited it in, not sure if it was in the right place or not*:

    Code:
    <?php
    $regTitle = "Page Title Here";
    define('TITLE',(isset($pTitle)) ? $pTitle : $regTitle);
    echo "<title>".TITLE."</title>";
    ?>
    Could you explain a bit more on how to go about entering the script into the index.php, and the s71.html, please feel free to view the source to see what i've done already.

    http://www.divxnaruto.com/index.php?id=s71.html or s71.php

    **I also think it might have something to do with the include code as well, maybe there is a function we need to add in order to get this to work. Thanks again for your time and patience.



    EDIT:
    I found a way to get it working, http://www.divxnaruto.com/s71-2.php

    This way works, I include the index.php into that page. Only problem is now changing all links accordingly to match, Is there anyway to get it to work with the original linking method index.php?id=
    Last edited by desception; 08-18-2008 at 02:31 PM.

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, I don't think that this is the best way, in fact. I know this isn't the best way. If there are protected files on your domain, people can get into the protected files, then they can do something... Lol. Can you give me the whole code to one of your pages so I can see whats wrong?
    Jeremy | jfein.net

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
  •