PDA

View Full Version : PHP Title Tag With Includes Problem....



desception
08-18-2008, 01:29 PM
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


<?

$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 :


<?php if (defined ('TITLE')) {
print TITLE;
} else {
print 'Watch Naruto Episodes Online | Bleach Episodes | Manga';
}
?>

and using this on the .html file :


<?php define ('TITLE', 'Page Title Here');
?>

I'm a no0b, and I really need some help. Thanks guys.

Nile
08-18-2008, 01:38 PM
Your on the right track. This should be in your HTML(well, it'd now be a PHP page. :)) page:


<?php
$regTitle = "Page Title Here";
define('TITLE',(isset($pTitle)) ? $pTitle : $regTitle;
echo "<title>".TITLE."</title>";
?>

Then in your code change:

<?php if (defined ('TITLE')) {
print TITLE;
} else {
print 'Watch Naruto Episodes Online | Bleach Episodes | Manga';
}
?>
To this:

<?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.

desception
08-18-2008, 02:07 PM
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*:


<?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=

Nile
08-19-2008, 01:52 AM
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?