Forum Moderators: coopster
<?php
$pagechecker = $_SERVER['REQUEST_URI'];
if($pagechecker = "pagechange")
{
echo '<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">';
}
else
{
echo '<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">';
}
?>
any URLs on my site that have "pagechange" as a parameter somewhere is a page adjusted slightly by the user and is therefore a duplicate page essentially. This code in the head tags I thought would be the easiest way to stop these duplicate pages being indexed?
Right now the code always returns the first option even if the URL of the page doesn't contain the parameter "pagechange".
Thanks
Mike
this
if($pagechecker = "pagechange")
should be
if($pagechecker == "pagechange")
as mentioned above
you could also look at preg_match [php.net]
try
Example#1 Find the string of text "php"
if($pagechecker == "pagechange")
and
if($pagechecker === "pagechange")
and all that did was make everything use the 2nd option. Could my problem be with ? The URL that is called is:
/uk/product.php?pagechange=483&ProdID=2
I'm not sure if I've done it right, but:
<?php
$pagechecker = $_SERVER['REQUEST_URI'];
if (preg_match("pagechange", $pagechecker))
{
echo '<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">';
}
else
{
echo '<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">';
}
?>
Also returns the second result every time.
Thanks
Mike
Tip
Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.
So switching to something like this would be faster:
if (strpos('pagechange', $pagechecker) !== false)