Jump to content

Archived

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

alexasigno

Simple IF statement to add hyperlink

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

Share this post


Link to post
Share on other sites
This:
[code]echo "<a href='http://www.sitea.com">";} [/code]
should be this:
[code]echo '<a href="http://www.sitea.com">';} [/code]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.