alexasigno Posted July 24, 2006 Share Posted July 24, 2006 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 changeAny ideas would be most appreciated.ThanksAlex Quote Link to comment https://forums.phpfreaks.com/topic/15510-simple-if-statement-to-add-hyperlink/ Share on other sites More sharing options...
wildteen88 Posted July 24, 2006 Share Posted July 24, 2006 This:[code]echo "<a href='http://www.sitea.com">";} [/code]should be this:[code]echo '<a href="http://www.sitea.com">';} [/code] Quote Link to comment https://forums.phpfreaks.com/topic/15510-simple-if-statement-to-add-hyperlink/#findComment-62969 Share on other sites More sharing options...
alexasigno Posted July 24, 2006 Author Share Posted July 24, 2006 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 welcomeThanks[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] Quote Link to comment https://forums.phpfreaks.com/topic/15510-simple-if-statement-to-add-hyperlink/#findComment-63007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.