I would like to use the get_browser() function in one of my scripts to display the user's info. I run the code (3 lines copied directly from php.net to see if it works) and I get this error:

Warning: get_browser(): browscap ini directive not set. in /home on line 33

Warning: Invalid argument supplied for foreach() in /home on line 35

My host has not installed a browscap.ini file, as the phpinfo() command says there is no path specified for that file. As far as I know, I cannot edit the php.ini file (don't have access to it). I have uploaded browscap.ini to my home directory, but is there any other way to get the php.ini file to point to the browscap.ini file I uploaded? In other words, how can this function work without editing the php.ini file? Thanks for any help! 😃

    unfortunately with this function there is no way to get it to work without editing php.ini or httpd.conf. you will need to ask your host to uncomment the browscap line and put the file somewhere on the server. this directive is only changable in php.ini or httpd.conf, not thru ini_set.

      Thanks for the reply. Perhaps there is another way to do what I want? Basically, I would like to gather as much information as possible about the user's computer. I want to take somewhat of a poll to see how many people use what browser, what hardware, OS, etc. so that I can better optimize my site. I want to know everything. 🙂

        there are a lot of javascript snippets out there that can do that. check out the different javascript sites.

          I'd rather use PHP if possible, I want to avoid javascript at all costs.

            php wont be able to get anything like what os the person is using or what kind of cpu they are on. the most you will be able to get is the browser and where they are from based on the ip.

              Hmm.. in the browser headers there usually is the Operating System they are on however you must now the headers to be able to convert that OS to its correct Operating System Name. However yes its true PHP cannot get there CPU, screen resolution.

              [ rapmonkey]

              There is no other way that i know of besides javascript the only thing there is that it can be turned off. However email your host about configuring the browser.ini basically its just a download and just put the correct path to the file in the php.ini

                I got this to work by loading a php.ini and browscap.ini into the dir and doing a system call to a php script to send back the get_browser() info.

                This way php used the local copy of php.ini and not the default one.
                A hard way to get something so simple, but it worked.

                $info = /usr/local/bin/php getbrowser.php

                <?
                print_r( get_browser() );
                ?>

                  So you mean by just putting this code, it will print what I want?

                  <?php
                  $info = `/pathtofile.ini` 
                  print_r( get_browser() ); 
                  ?>

                    In your main script put the system call

                    $info = /usr/local/bin/php getbrowser.php

                    in a seperate file called getbrowser.php put
                    <?
                    print_r( get_browser() );
                    ?>
                    Make sure you have edited php.ini to point to the browscap.ini
                    and that it is in the same dir as getbrowser.php

                      This should work, but it seems I have something wrong with my foreach statement. This code:

                      <?
                      $info = `/home/ getbrowser.php`;
                      
                      foreach ($info as $item => $val) {
                      echo "<b>$item</b> $val <br />\n";
                      }
                      ?>
                      

                      Returns this error:

                      Warning: Invalid argument supplied for foreach() in /home/main.php on line 35

                        That means you are not getting an array into $info

                        could it be:

                        $info = /home/getbrowser.php;
                        instead?

                          I can't get it. 🙁

                          Here is how everything is set up.

                          /home/scripts contains main.php, getbrowser.php, browscap.ini, and php.ini. main.php has the following code:

                          <?php
                          $info = `/home/scripts/getbrowser.php`;
                          
                          foreach ($info as $item => $val) {
                          echo "<b>$item</b> $val <br />\n";
                          }
                          ?>

                          getbrowser.php has the following code:

                          <?php
                          print_r( get_browser() );
                          ?>

                          Yet I get this error: Warning: Invalid argument supplied for foreach() in /home/scripts/main.php on line 37

                          What is going wrong?

                            oops, didnt read carefully.

                            Basically, HalfaBee's idea is to use the PHP interpreter from command line.

                            //main script
                            $info = `/path/to/php getbrowser.php`;
                            print_r($info); //see if it is correct
                            
                            //getbrowser.php
                            <?php
                            print_r(get_browser());
                            ?>

                              I tried this earlier...No error, but no output either.

                                Still having a problem...Now I get no errors but no output. I'm not quite sure I understand the PHP interpreter via the command line. How does this work?

                                  Try doing
                                  <?
                                  passthru('ls -la /usr/local/bin/php' );
                                  ?>

                                  to see if it is actually there.

                                  You can also do this to see where it is
                                  <?
                                  echo '<PRE>';
                                  passthru( 'locate php' );
                                  ?>

                                  PHP is just a program that you can run on the server.
                                  Just like doing ls or ps

                                    The first command returns this:

                                    rwxr-xr-x 1 root root 7429677 Mar 9 08:02 /usr/local/bin/php

                                    while the 2nd command returns a LOT of stuff. I still don't see how all of this works.🙁

                                      It shows php is available and you can run it.

                                        OK, getbrowser.php has this code:

                                        <?php
                                        //print_r( get_browser() );
                                        echo get_browser($_SERVER['argv'][0]);
                                        ?>

                                        main.php has this code:

                                        <?php
                                        $info = `/path/to/dir getbrowser.php`;
                                        
                                        print_r($info);
                                        ?>

                                        /path/to/dir is the path to browscap.ini as well as php.ini and the scripts I am running (getbrowser.php and main.php). Same problem. No errors and no output.