Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

How can I get information about the user's browser?

( #21553=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Jul 07, 2000 at 22:48 UTC
Q&A  > CGI programming


Description:

I have a simple socket server that I would like to add the capability to retreive info on the user. The problem is, connection is called from the html page using a image reference. How would I go about to getting user info. Like browser type and his IP.

Answer: How can I get information about the user's browser?
contributed by nardo

The web browser will send info about itself in the User-Agent line. A browser might send you something like:

GET / HTTP/1.0 Connection: Keep-Alive User-Agent: Mozilla/4.72 [en] (X11; U; Linux 2.2.16 i686) Host: localhost:1101 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png +, */* Accept-Encoding: gzip Accept-Language: en Accept-Charset: iso-8859-1,*,utf-8
Answer: How can I get information about the user's browser?
contributed by wardk

using CGI.pm

use CGI; my $q = new CGI(); my $UserAgent = $q->user_agent(); ...
Answer: How can I get information about the user's browser?
contributed by ybiC

I'm not clear on what you mean by "called from the html page using a image reference", and this may not apply since you're using "a simple socket server", but I use the following environment variables from CGI.pm.

$ENV{'REMOTE_HOST'} $ENV{'REMOTE_ADDR'} $ENV{'HTTP_USER_AGENT'}

If this is what you're looking for, more info can be found at http://stein.cshl.org/WWW/software/CGI/.

No mater how you extract this info, it's trivially spoofed, so you shouldn't base any security on what browsers tell you about themselves.
    cheers,
    ybiC

Answer: How can I get information about the user's browser?
contributed by hacker

Or, slap this in a page and see the entire environment that is passed in the request:

use Env; print "<!--\n"; foreach $parameter ( sort keys %ENV ) { print "$parameter is: $ENV{$parameter}\n"; }
Answer: How can I get information about the user's browser?
contributed by sinan

Check out Environmental Variables for an program that lists the env. variables.

Answer: How can I get information about the user's browser?
contributed by cleen

yes, user-agent line, a web client will send a series of plain text lines that tell the server what types of files it accepts, what domain name its looking for (for ipless hosts), and included within that data is a line that is simply called the "User-Agent" line. Everything after the User-Agent: is the type of browser and operating system they are using.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2015-07-04 16:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls