Jump to content

Simple IF statement to add hyperlink


alexasigno

Recommended Posts

Well my knowledge of php is even poorer than first imagined! Im trying to do something simple but jsut cant get it to work and would really appreiciate some help.

Im trying to detect whether the user agent is a robot and if it is to send it to one page, and if its not to send it to another.

[code]<html>
<head>
<title>Test</title>
</head>
<body>

<?php

$botlist = array("alexa", "appie", "Ask Jeeves", "crawler", "FAST",
"froogle", "Firefly", "girafabot", "Googlebot", "InfoSeek", "inktomi",
"looksmart", "NationalDirectory", "rabaz", "Scooter", "Slurp", "Spade",
"TECNOSEEK", "Teoma", "WebBug", "WebFindBot", "URL_Spider_SQL",
"ZyBorg");

                function detectBrowser($agent) {
                                    if (eregi("botlist", $agent)) {
                                        $browser = "Bot";
                      } else {
                                        $browser = "Browser";
                      }
                                return $browser;
                }
?>

<?php

$user_agent = $HTTP_SERVER_VARS["HTTP_USER_AGENT"];
$isBrowser = detectBrowser($user_agent);

if ($isBrowser=="Bot") {
echo "<a href='http://www.sitea.com">";}

else {
echo "<a href='http://www.siteb.com">";


}
?>


</body>
</html>[/code]

But im not quite sure what im doing wrong? I dont want to redirect the user i just want the hyperlink to change

Any ideas would be most appreciated.

Thanks
Alex
Link to comment
https://forums.phpfreaks.com/topic/15510-simple-if-statement-to-add-hyperlink/
Share on other sites

Thankyou wildteen88 school boy error!!!  ::)

I have changed the code to the following, it is writing the urls but is not changing when seen by a bot?

Any ideas most welcome

Thanks

[code]<html>
<head>
<title>Test</title>
</head>
<body>

<?php

$botlist = array("alexa", "appie", "Ask Jeeves", "crawler", "FAST",
"froogle", "Firefly", "girafabot", "Googlebot", "InfoSeek", "inktomi",
"looksmart", "NationalDirectory", "rabaz", "Scooter", "Slurp", "Spade",
"TECNOSEEK", "Teoma", "WebBug", "WebFindBot", "URL_Spider_SQL",
"ZyBorg");

                function detectBrowser($agent) {
                                    if (eregi("botlist", $agent)) {
                                        $browser = "Bot";
                      } else {
                                        $browser = "Browser";
                      }
                                return $browser;
                }
?>

<?php

$user_agent = $HTTP_SERVER_VARS["HTTP_USER_AGENT"];
$isBrowser = detectBrowser($user_agent);
if ($isBrowser=="Bot") {

echo '<a href="http://www.sitea.com">site a</a>';


} else {

echo '<a href="http://www.siteb.com">site b</a>';


}
?>


</body>
</html>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.