Jump to content


Photo

Simple IF statement to add hyperlink


  • Please log in to reply
2 replies to this topic

#1 alexasigno

alexasigno
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 July 2006 - 04:37 PM

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.

<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>

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 July 2006 - 04:39 PM

This:
echo "<a href='http://www.sitea.com">";}
should be this:
echo '<a href="http://www.sitea.com">';}


#3 alexasigno

alexasigno
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 July 2006 - 05:31 PM

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

<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>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users