Cant write Browser, OS with browser detections cript
Status: New User - Welcome
Joined: 20 Jul 2004
Posts: 1
Location: NC, USA
Reply Quote
Below is my code. it is simply the PHP Browser detection script and down at the bottom I try to write the browser and OS. it doesnt write anything except for those "<br>"s that i put in after it.

whats the problem?

:: Code ::

[edited out browser detection script, not necessary in this case]

   $bName = browser_detection('browser');
   $osName = browser_detection('os');
   $bNum = browser_detection('number');
   $osNum = browser_detection('os_number');

   echo $bName ."<br>";
   echo $osName ."<br>";
   echo $bNum ."<br>";
   echo $osNum ."<br>";


Back to top
No problem in the code you posted
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Hi John, welcome to the Tech Forums.

I cut and pasted the code you posted without changing anything, and it worked fine, output exactly what you wanted it to output.

It looks like you have a server configuration problem of some kind, I can't tell you what it is. What are you running this code on, Apache 1.3, 2.0, php for IIS, php 4.3, 4.0?

Is it a linux or windows server, your development server or a webhost server?
Back to top
Erik Johnson
Status: Interested
Joined: 26 Sep 2003
Posts: 17
Reply Quote
Although this almost definitely isn't the problem, you might want to think about using the <?php ?> type syntax instead of the <? ?>, it's a good habit to get into, especially if you are ever going to be doing xml type stuff, keeps the code more forware compatible.

However, that's almost for sure not the problem, but check it just in case, what's happening is that the code isn't running right, although some of it is, since your page is outputting the <br>, or I assume it is from the sound of it (that means the page contains only the HTML <br>.

The way to check this is to look at the source code and see what is being output, if it's just the page html and then the <br>, and the php is not there, your server is working sort of, but not completely.

Are you sure that your browser has a navigator user agent? If you have a test browser it's possible for some, like Firefox/Safari/Konqueror to actually have no navigator user agent, and in this case, that would give a similar result, that is, blank.

A test for this would be something like this:

:: Code ::
if ( browser_detection('browser') != '' )
  echo browser_detection('browser')  . '<br>';
  echo 'no browser detected<br>';

This test will quickly show if your php is working, and where the problem is.

In general, it's a good idea to program in failsafes, or defaults, and never to assume that there is going to be an output, that tends to lead to increasingly serious problems. For example, in an earlier version of the browser detection script, there was a bug that triggered when no operating system was identified, but since we tested this only on windows, we didn't find that bug for about 3 weeks, that was because we'd forgotten to add a default not found value for the os detection part of the script, and to test the actual output

We now use the fantastic Firefox Extension user agent switcher by Chris Pederick, author of the equally great Web Developer Toolbar..

Let me know if any of these things were the problem, thanks, Erik (and welcome to the forums, by the way)
Back to top
Display posts from previous:   

All times are GMT - 8 Hours