http://qs321.pair.com?node_id=21553

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (cgi programming)

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.

Originally posted as a Categorized Question.

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

Replies are listed 'Best First'.
Re: How can I get information about the user's browser?
by nardo (Friar) on Jul 08, 2000 at 03:44 UTC
    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
Re: How can I get information about the user's browser?
by wardk (Deacon) on Aug 22, 2000 at 01:16 UTC

    using CGI.pm

    use CGI; my $q = new CGI(); my $UserAgent = $q->user_agent(); ...
Re: How can I get information about the user's browser?
by ybiC (Prior) on Aug 22, 2000 at 05:43 UTC
    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

Re: How can I get information about the user's browser?
by hacker (Priest) on Nov 17, 2001 at 16:12 UTC
    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"; }
Re: How can I get information about the user's browser?
by sinan (Sexton) on Aug 27, 2000 at 12:48 UTC
Re: How can I get information about the user's browser?
by cleen (Pilgrim) on Jul 08, 2000 at 15:07 UTC
    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.