PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
wow, i was not aware of that... i'm working with somebody else's code... that's weird... i renamed it to get_browser_type() and it didn't bring me any errors, but then again it didn't print anything either. i added
I wrote a little something once to check if the browser is IE (because standard browsers can hack it, but IE chokes on standards). It might not be exactly what you want, but it might be helpful in some capacity.
<?php
/**
* Checks if the users browser is internet explorer
* @access public
* @return boolean Returns true is the browser is IE, false otherwise
*/
public function check_ie_browser()
{
// Get the users browser
$useragent = $_SERVER['HTTP_USER_AGENT'];
// Look for IEs fingerprint
if (strpos($useragent, 'MSIE') !== false && strpos($useragent, 'Opera') === false && strpos($useragent, 'Netscape') === false)
{
// Read and check the result
if (preg_match("/MSIE ([0-9]{1}\.[0-9]{1,2})/", $useragent))
{
return true;
}
}
return false;
}
?>
thanks feyd... i wondered why it was highlighted when i typed in that function name in my vim editor, but when i searched php.net/get_browser it didn't bring anything up... i should have typed in php.net/function.get_browser. thank you feyd, and Everah.
everah, nice function. tell me, what is the purpose of adding 'public' before you begin the function. and what would it return if you printed the returned value of that function? how did you use it within your existing code?
visitor-Q wrote: tell me, what is the purpose of adding 'public' before you begin the function. and what would it return if you printed the returned value of that function? how did you use it within your existing code?
Public is a class visibility declaration. It is used in PHP5 OOP. Basically it makes the function available to the entire application for use.
Basically all it does is tell you whether your user is using IE or not. So it returns true if the browser is IE, false otherwise. It can be used like...
thank's for the info everah. i'm not familiar with OOP, but i'm not too fond of using classes with PHP. it is my understanding that some people swear by it, yet others despise it. is it necessary to evolve to understand/use classes at a high-level of PHP programming?
Code how you feel most comfortable with. There have been many a heated debate over procedural versus OO programming, and I am not about to open that can of crap again. If you are more of a procedural style coder, keep going. At some point I would venture to say that you will need to learn OOP just so you can keep up with evolving codebases. But for your own projects, you should be alright to code how you want.