PHP to Solve Google Duplicate Headers issue...

I have a directory website that displays results over several pages. Google analytics flags up an issue with using the same header for several of these page (duplicate headers).

I want to use the variable $page (page number) derived from

if(!isset($_GET[‘page’])){
$page = 1;
} else {
$page = $_GET[‘page’];
}

And add this to the header description to give each page a unique header and thus satisfy Google.

The problem…

<?php print ("$page-XXXXXXDescriptionXXXXXXX "); ?>

The php for creating the unique header executes before the do while loop, DB connection, building of the results and the generation of pagination ($page).

Is there an easy way, apart from rewriting all the pages of passing the variable back to the header script???

Would using $_SESSION[’’]; work on a page that recalls itself with the prev & next links?:-

if($page > 1){
$prev = ($page - 1);
echo “<a href=”".$_SERVER[‘PHP_SELF’]."?page=$prev">Prev ";
}

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo “$i “;
} else {
echo “<a href=””.$_SERVER[‘PHP_SELF’].”?page=$i">$i ";
}
}

// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo “<a href=”".$_SERVER[‘PHP_SELF’]."?page=$next">Next";
echo “

”;
}
}

Any help appreciated.
Regards
Graham

$_SESSION will work for people/browsers, but not for Google bot.
To avoid restructuring PHP/HTML code on all the pages, you can try to use Output Control Functions: ob_start(), ob_get_contents(), ob_end_clean() etc. to save generated content into string variable. And before outputting anything to browser - update tag.

Here is example:
[php]<?php
ob_start();
?>

<?php // generate html page (any current html/php code here)

// generate title tag
$title = $page.’ — any content read from database here —’;
?>

<?php $content = ob_get_contents(); ob_end_clean(); $content = str_replace('',''.$title.'',$content); echo $content; ?> [/php]

So, basically you need to add ob_start() at top of your current script, then these several lines at bottom of script. Hope this will give you idea.

Thanks will give that a go.
Didn’t know about that function…

Regards
Graham

Sponsor our Newsletter | Privacy Policy | Terms of Service