php detect web browser

01.<?php
02.$useragent = $_SERVER[‘HTTP_USER_AGENT’]);
03. 
04.if (preg_match(‘|MSIE ([0-9].[0-9]{1,2})|’,$useragent,$matched)) {
05.    $browser_version=$matched[1];
06.    $browser = ‘IE’;
07.} elseif (preg_match( ‘|Opera ([0-9].[0-9]{1,2})|’,$useragent,$matched)) {
08.    $browser_version=$matched[1];
09.    $browser = ‘Opera’;
10.} elseif(preg_match(‘|Firefox/([0-9\.]+)|’,$useragent,$matched)) {
11.        $browser_version=$matched[1];
12.        $browser = ‘Firefox’;
13.} elseif(preg_match(‘|Safari/([0-9\.]+)|’,$useragent,$matched)) {
14.        $browser_version=$matched[1];
15.        $browser = ‘Safari’;
16.} else {
17.        // browser not recognized!
18.    $browser_version = 0;
19.    $browser= ‘other’;
20.}
21. 
22.print “browser: $browser $browser_version”;
23.?>

Show / Hide a table with Javascript

01.<script type="text/JavaScript">
02. 
03.<!--
04.function show(id)
05.{
06.     if (document.getElementById(id).style.display == 'none')
07.     {
08.          document.getElementById(id).style.display = '';
09.     }
10.}
11.//-->
12. 
13.<!--
14.function hide(id)
15.{
16.          document.getElementById(id).style.display = 'none';
17. 
18.}
19.//-->
20.</script>
21. 
22. 
23.<table cellspacing="1" cols="3" border="0">
24.    <tbody>
25.    <tr valign="top" align="left">
26.      <td width="202"><b>Please, select option</b></td>
27. 
28.      <td width="481">A
29.        <input type="radio" name="Option" onfocus="hide('tblB');hide('tblC');show('tblA');">
30.        B
31.        <input type="radio" name="Option"  onfocus="hide('tblA');hide('tblC');show('tblB');return true;">
32.        C     
33.        <input type="radio" name="Option" onfocus="hide('tblA');hide('tblB');show('tblC');return true;">
34.      </td>
35.    </tr>
36.    </tbody>
37.  </table>
38.   
39. 
40.  <table id="tblA" style="DISPLAY: none" cols="1" cellpadding="2">
41.    <tbody>
42.    <tr valign="top" align="left">
43.      
44.    <td>
45.      You&nbsp;select A,
46.      table
47.      tblA is shown&nbsp;
48.      </td>
49.    </tr>
50.    </tbody>
51.  </table>
52.  <table id="tblB" style="DISPLAY: none" cols="1" cellpadding="2">
53.    <tbody>
54.    <tr valign="top" align="left">
55.      <td>
56.       You&nbsp;select B, table tblB
57.       is shown&nbsp;
58.      </td>
59.    </tr>
60.    </tbody>
61.  </table>
62.   <table id="tblC" style="DISPLAY: none" cols="1" cellpadding="2">
63.    <tbody>
64.    <tr valign="top" align="left">
65.      <td>
66.       You&nbsp;select C, table tblC
67.       is shown&nbsp;
68.      </td>
69.    </tr>
70.    </tbody>
71.  </table>