Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Use function_exists to test that a function is available, either natively or defined
previously by PHP code.


<?
$function = "date";
if(function_exists($function))
{
print($function. " exists");
}
?>


object get_browser(string user_agent)


The get_browser function works with the browscap.ini (browser capabilities) file to
report the capabilities of a browser. The user_agent argument is the text a browser
identifies itself with during an HTTP transaction. If you leave out this argument, PHP
uses HTTP_USER_AGENT, a variable created by PHP for you. The argument is matched
against all the browsers in the browscap.ini file. When a match occurs, each of the
capabilities becomes a property in the object returned.


The location of the browscap.ini file is specified in php.ini using the browscap
directive. If the directive is not used, or PHP can't match a browser to an entry in your
browscap.ini file, no error will be produced. However, the returned object will have no
properties.


Microsoft provides a browscap.ini file for use with its Web server, but it is not freely
distributable. In response, PHP has an official browscap.ini file. It may be found at
http://php.netvision.net.il/browscap/ and depends on contributions. At the time of
this writing, it appeared to be abandoned. Alternatively, you may wish to get a
browscap.ini from Web developer cyScape at
<http://www.cyscape.com/asp/browscap/ >. Be aware you are required to register first.


<?
$browser = get_browser();
print("You are using ". $browser->browser. "
\n");
if($browser->javascript)
{
print("Your browser supports JavaScript.
\n");
}
?>


string get_cfg_var(string variable)

Free download pdf