Hello people, well, i was developing a page where i wanna limit the access to only certain browsers.. 'coz i dont want bots (specially auto clickers) lurking around on that page not even search engines. So I wrote the following code using $_SERVER['HTTP_USER_AGENT'] , but then a doubt struck me... do autoclickers use browsers of their own or the user's browser for navigation. can anyone clear this doubt for me and if they do use browser's how can i program the page only to be seen by certain browsers. Thanks in advance, regards, rahul
well, autoclickers made in PHP can usually disguise themselves as web browsers when they are not, I have a small suggestion, make your site fully session enabled, then pass a small variable for each session and verify it on every page, that way it might prevent autoclickers, you can also use the HTTP_REFERRER to check if the users has come from a previous page or directely.
Most use a fake user-agent string to fake the server into serving them the page. I really don't know how you would go about checking validity, unless it was using a Robot (googlebot, etc) useragent. If they're faking a googlebot user agent, or any other user agent for that matter that corresponds to a webcrawler bot, you could verify the domain name in their connection string, resolve that back to the IP, and then get the $_Server['Remote_Address'] or _Server['Remote_Host'] and verify that they jive
also, if you're sure it's the googlebot, you can just save its ips and afterwards tell if it's someone else just "trying to play around".
well i dont need that on every page, just on one page(the most crucial) and i have sessions enabled thats how i manage user's login( using mysql_real_escape_string() and a checkerr() function i made), i have considered security but the problem is if autoclicker's can access the page (though i have additional security but i am too paranoid about security ) , what good'd HTTP_REFERRER do, i dont wanna block coming from other website. I have protected my page from everything(bots or unknown browser) but a few webbrowsers... and i dont mind google bots much. the main problem are autoclickers. let me show you the code... here's the class for detection of browser. (in a php file called "check.php") <?php class Browser { private $_agent = ''; private $_browser_name = ''; private $_version = ''; private $_platform = ''; private $_os = ''; private $_is_aol = false; private $_aol_version = ''; const BROWSER_UNKNOWN = 'unknown'; const VERSION_UNKNOWN = 'unknown'; const BROWSER_OPERA = 'Opera'; const BROWSER_WEBTV = 'WebTV'; const BROWSER_NETPOSITIVE = 'NetPositive'; const BROWSER_IE = 'Internet Explorer'; const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; const BROWSER_GALEON = 'Galeon'; const BROWSER_KONQUEROR = 'Konqueror'; const BROWSER_ICAB = 'iCab'; const BROWSER_OMNIWEB = 'OmniWeb'; const BROWSER_PHOENIX = 'Phoenix'; const BROWSER_FIREBIRD = 'Firebird'; const BROWSER_FIREFOX = 'Firefox'; const BROWSER_MOZILLA = 'Mozilla'; const BROWSER_AMAYA = 'Amaya'; const BROWSER_LYNX = 'Lynx'; const BROWSER_SAFARI = 'Safari'; const BROWSER_IPHONE = 'iPhone'; const BROWSER_CHROME = 'Chrome'; const PLATFORM_UNKNOWN = 'unknown'; const PLATFORM_WINDOWS = 'Windows'; const PLATFORM_WINDOWS_CE = 'Windows CE'; const PLATFORM_APPLE = 'Apple'; const PLATFORM_LINUX = 'Linux'; const PLATFORM_OS2 = 'OS/2'; const PLATFORM_BEOS = 'BeOS'; const OPERATING_SYSTEM_UNKNOWN = 'unknown'; const BROWSER_INTERNET_EXPLORER = 'ie'; public function Browser() { $this->reset(); $this->determine(); } public function reset() { $this->_agent = $_SERVER['HTTP_USER_AGENT']; $this->_browser_name = self::BROWSER_UNKNOWN; $this->_version = self::VERSION_UNKNOWN; $this->_platform = self::PLATFORM_UNKNOWN; $this->_os = self::OPERATING_SYSTEM_UNKNOWN; $this->_is_aol = false; $this->_aol_version = self::VERSION_UNKNOWN; } function isBrowser($browserName) { return( 0 == strcasecmp($this->_browser_name, trim($browserName))); } public function getBrowser() { return $this->_browser_name; } public function setBrowser($browser) { return $this->_browser_name = $browser; } public function getPlatform() { return $this->_platform; } public function setPlatform($platform) { return $this->_platform = $platform; } public function getVersion() { return $this->_version; } public function setVersion($version) { $this->_version = ereg_replace('[^0-9,.,a-z,A-Z]','',$version); } public function getAolVersion() { return $this->_aol_version; } public function setAolVersion($version) { $this->_aol_version = ereg_replace('[^0-9,.,a-z,A-Z]','',$version); } public function isAol() { return $this->_is_aol; } public function setAol($isAol) { $this->_is_aol = $isAol; } public function getUserAgent() { return $this->_agent; } public function setUserAgent($agent_string) { $this->reset(); $this->_agent = $agent_string; $this->determine(); } protected function determine() { $this->checkPlatform(); $this->checkBrowsers(); $this->checkForAol(); } protected function checkBrowsers() { return ( $this->checkBrowserInternetExplorer() || $this->checkBrowserFirefox() || $this->checkBrowserChrome() || $this->checkBrowserSafari() || $this->checkBrowserOpera() || $this->checkBrowserNetPositive() || $this->checkBrowserFirebird() || $this->checkBrowserGaleon() || $this->checkBrowserKonqueror() || $this->checkBrowserIcab() || $this->checkBrowserOmniWeb() || $this->checkBrowserPhoenix() || $this->checkBrowserWebTv() || $this->checkBrowserAmaya() || $this->checkBrowserLynx() || $this->checkBrowseriPhone() || $this->checkBrowserMozilla()); } protected function checkForAol() { $retval = false; if( eregi("AOL", $this->_agent) ) { $aversion = explode(' ',stristr($this->_agent, "AOL")); $this->setAol(true); $this->setAolVersion(ereg_replace("[^0-9,.,a-z,A-Z]", "", $aversion[1])); $retval = true; } else { $this->setAol(false); $this->setAolVersion(self::VERSION_UNKNOWN); $retval = true; } return $retval; } protected function checkBrowserInternetExplorer() { $retval = false; if( eregi('microsoft internet explorer', $this->_agent) ) { $this->setBrowser(self::BROWSER_IE); $this->setVersion('1.0'); $aresult = stristr($this->_agent, '/'); if( egeg('308|425|426|474|0b1', $var) ) { $this->setVersion('1.5'); } $retval = true; } else if( eregi('msie',$this->_agent) && !eregi('opera',$this->_agent) ) { $aresult = explode(' ',stristr(str_replace(';','; ',$this->_agent),'msie')); $this->setBrowser( self::BROWSER_IE ); $this->setVersion($aresult[1]); $retval = true; } else if( eregi('mspie',$this->_agent) || eregi('pocket', $this->_agent) ) { $aresult = explode(' ',stristr($this->_agent,'mspie')); $this->setPlatform( self::PLATFORM_WINDOWS_CE ); $this->setBrowser( self::BROWSER_POCKET_IE ); if( eregi('mspie', $this->_agent) ) { $this->setVersion($aresult[1]); } else { $aversion = explode('/',$this->_agent); $this->setVersion($aversion[1]); } $retval = true; } return $retval; } protected function checkBrowserOpera() { $retval = false; if( eregi('opera',$this->_agent) ) { $resultant = stristr($this->_agent, 'opera'); if( eregi('/',$resultant) ) { $aresult = explode('/',$resultant); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->_browser_name = self::BROWSER_OPERA; $retval = true; } else { $aversion = explode(' ',stristr($resultant,'opera')); $this->setVersion($aversion[1]); $this->_browser_name = self::BROWSER_OPERA; $retval = true; } } return $retval; } protected function checkBrowserWebTv() { $retval = false; if( eregi('webtv',$this->_agent) ) { $aresult = explode("/",stristr($this->_agent,"webtv")); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->_browser_name = self::BROWSER_WEBTV; $retval = true; } return $retval; } protected function checkBrowserNetPositive() { $retval = false; if( eregi('NetPositive',$this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'NetPositive')); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->_browser_name = self::BROWSER_NETPOSITIVE; $this->_platform = self::PLATFORM_BEOS; $retval = true; } return $retval; } protected function checkBrowserGaleon() { $retval = false; if( eregi('galeon',$this->_agent) ) { $aresult = explode(' ',stristr($this->_agent,'galeon')); $aversion = explode('/',$aresult[0]); $this->setVersion($aversion[1]); $this->setBrowser(self::BROWSER_GALEON); $retval = true; } return $retval; } protected function checkBrowserKonqueror() { $retval = false; if( eregi('Konqueror',$this->_agent) ) { $aresult = explode(' ',stristr($this->_agent,'Konqueror')); $aversion = explode('/',$aresult[0]); $this->setVersion($aversion[1]); $this->setBrowser(self::BROWSER_KONQUEROR); $retval = true; } return $retval; } protected function checkBrowserIcab() { $retval = false; if( eregi('icab',$this->_agent) ) { $aversion = explode(' ',stristr(str_replace('/',' ',$this->_agent),'icab')); $this->setVersion($aversion[1]); $this->setBrowser(self::BROWSER_ICAB); $retval = true; } return $retval; } protected function checkBrowserOmniWeb() { $retval = false; if( eregi('omniweb',$this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'omniweb')); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->setBrowser(self::BROWSER_OMNIWEB); $retval = true; } return $retval; } protected function checkBrowserPhoenix() { $retval = false; if( eregi('Phoenix',$this->_agent) ) { $aversion = explode('/',stristr($this->_agent,'Phoenix')); $this->setVersion($aversion[1]); $this->setBrowser(self::BROWSER_PHOENIX); $retval = true; } return $retval; } protected function checkBrowserFirebird() { $retval = false; if( eregi('Firebird',$this->_agent) ) { $aversion = explode('/',stristr($this->_agent,'Firebird')); $this->setVersion($aversion[1]); $this->setBrowser(self::BROWSER_FIREBIRD); $retval = true; } return $retval; } protected function checkBrowserFirefox() { $retval = false; if( eregi('Firefox',$this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'Firefox')); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->setBrowser(self::BROWSER_FIREFOX); $retval = true; } return $retval; } protected function checkBrowserMozilla() { $retval = false; if( eregi('Mozilla',$this->_agent) && eregi('rv:[0-9].[0-9][a-b]',$this->_agent) && !eregi('netscape',$this->_agent)) { $aversion = explode(' ',stristr($this->_agent,'rv:')); eregi('rv:[0-9].[0-9][a-b]',$this->_agent,$aversion); $this->setVersion($aversion[0]); $this->setBrowser(self::BROWSER_MOZILLA); $retval = true; } else if( eregi('mozilla',$this->_agent) && eregi('rv:[0-9]\.[0-9]',$this->_agent) && !eregi('netscape',$this->_agent) ) { $aversion = explode(" ",stristr($this->_agent,'rv:')); eregi('rv:[0-9]\.[0-9]\.[0-9]',$this->_agent,$aversion); $this->setVersion($aversion[0]); $this->setBrowser(self::BROWSER_MOZILLA); $retval = true; } return $retval; } protected function checkBrowserLynx() { $retval = false; if( eregi('libwww',$this->_agent) && eregi("lynx", $this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'Lynx')); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->setBrowser(self::BROWSER_LYNX); $retval = true; } return $retval; } protected function checkBrowserAmaya() { $retval = false; if( eregi('libwww',$this->_agent) && eregi("amaya", $this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'Amaya')); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->setBrowser(self::BROWSER_AMAYA); $retval = true; } return $retval; } protected function checkBrowserChrome() { $retval = false; if( eregi('Chrome',$this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'Chrome')); $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); $this->setBrowser(self::BROWSER_CHROME); $retval = true; } return $retval; } protected function checkBrowserSafari() { $retval = false; if( eregi('Safari',$this->_agent) && ! eregi('iPhone',$this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'Version')); if( isset($aresult[1]) ) { $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); } else { $this->setVersion(self::VERSION_UNKNOWN); } $this->setBrowser(self::BROWSER_SAFARI); $retval = true; } return $retval; } protected function checkBrowseriPhone() { $retval = false; if( eregi('iPhone',$this->_agent) ) { $aresult = explode('/',stristr($this->_agent,'Version')); if( isset($aresult[1]) ) { $aversion = explode(' ',$aresult[1]); $this->setVersion($aversion[0]); } else { $this->setVersion(self::VERSION_UNKNOWN); } $this->setBrowser(self::BROWSER_IPHONE); $retval = true; } return $retval; } protected function checkPlatform() { if( eregi("win", $this->_agent) ) { $this->_platform = self::PLATFORM_WINDOWS; } elseif( eregi("mac", $this->_agent) ) { $this->_platform = self::PLATFORM_APPLE; } elseif( eregi("linux", $this->_agent) ) { $this->_platform = self::PLATFORM_LINUX; } elseif( eregi("OS/2", $this->_agent) ) { $this->_platform = self::PLATFORM_OS2; } elseif( eregi("BeOS", $this->_agent) ) { $this->_platform = self::PLATFORM_BEOS; } } } ?> PHP: and here's the page code where i am using the class... <? include("check.php"); $browser = new Browser(); if( $browser->getBrowser() == Browser::BROWSER_UNKNOWN) { echo "You are using an unknown browser or an auto application! please use a decent browser to view this page"; } else { // the page code } ?> PHP: as you might have noticed the class uses its best guess on user-agents but you say they can be faked so i want a solution through it... Anyway, thanks for your replies