Show Different "Code/Words" Based on URL Referer
I'm trying to have my website not show certain code if they come from certain URL's.
For example, Wikipedia don't like links to sites that have popups on them. So I need to not show the code for that referer.
I found the following code but it doesn't seem to work when code is places instead of text
<?php $ref=getenv('HTTP_REFERER');
if (strpos($ref,"google.com")>0)
{
echo "google";
}
else
{
echo "something开发者_开发技巧 else";
};
?>
If you want to avoid showing code to google:
<?php if (!strstr(strtolower($_SERVER['HTTP_USER_AGENT']),"googlebot")){ ?>
//Show what you want, google will not see it
}else{
//show other code
}?>?>
For wikipedia:
<?php if (!strstr(strtolower($_SERVER['HTTP_REFERER']),"wikipedia")){ ?>
//Show what you want, wikipedia will not see it
}else{
//show other code
}?>
Enjoy ;)
You were talking about Wikipedia. Probably the problem is that google isn't sending you "google" in their referer string
it must work, try alternative variable
<?php
$ref=$_SERVER['HTTP_REFERER'];
if (strpos($ref,"google.com")>0)
{
echo "google";
}
else
{
echo "something else";
};
?>
精彩评论