|  | Posted by deko on 02/08/07 17:17 
> $refhost = preg_replace('/\&/', '\&\;', $refhost);
 I think this will work, but htspecialchars() might be a better fit here.
 
 Another situation where preg_replace() might be better is this:
 
 Let's say I get a visitor using the following agent:
 
 <a href="http://netforex.net"> Forex Trading Network Organization </a>
 info@netforex.org
 
 This indicates a robot (not a real visitor), so I want to identify it as such
 with this code:
 
 //well-known browsers
 if(eregi("firefox.",$agent))
 {
 $browser = "firefox";
 }
 elseif(eregi("other browsers")
 {
 $browser = "other browsers";
 }
 //well-known bots
 elseif (eregi("(bot|google|slurp|scooter|spider|infoseek|[etc., etc.])",
 $agent))
 {
 $browser = "bot";
 }
 //unknown bots - identified by having a URL in the agent srting
 elseif (eregi("http://", $agent))
 {
 $agent = stristr($agent, "http://");
 $agent = parse_url($agent);
 $agent = $agent['host'];
 $agent_a = explode(".", $agent);
 $agent_r = array_reverse($agent_a);
 $sub = count($agent_r) - 1;
 $tld3 = substr($agent_r[0], 0, 3);
 if (eregi("^(com|net|org|edu|biz|gov)$", $tld3)) //common tld's
 {
 while ($sub > 0)
 {
 $domain = $domain.$agent_r[$sub].".";
 $sub--;
 }
 $refurl = $domain.$tld3; //use for building referring site link
 }
 $browser = "bot";
 }
 else
 {
 $browser = "unknown";
 }
 
 I know this is kind of a hack... any thoughts for improvement?
  Navigation: [Reply to this message] |