473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Unable to print $ENV{'HTTP_USER_AGENT'} ?

135 100+
When I run the code below, the $ENV{'HTTP_USER_AGENT'} is coming up blank, I'm saved the file under .pl and .cgi extensions and still I can't display the browser name.

For this reason the code below goes straight to the else statement, In actual fact I'm using IE.

Where I'm I going wrong?


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. print "Content-type:text/html\n\n";
  4. print "<html><head><title>Welcome</title></head>\n";
  5. print"<body>\n";
  6. print "Browser: $ENV{'HTTP_USER_AGENT'}<p>\n"; # $ENV is blank here!!
  7.  
  8. if ($ENV{'HTTP_USER_AGENT'}=~/MSIE/) {
  9.     print "Your using <b>IE</b><p>\n";
  10. }  elsif ($ENV{'HTTP_USER_AGENT'}=~/Mozilla/) {
  11.     print "Your using <b>Netscape!</b><p>\n";
  12. }  else {
  13.     print "Your using a browser other than IE & Mozilla\n";
  14. }
  15.  
  16. print "</body></html>\n"; 
Sep 6 '07 #1
7 4133
miller
1,089 Expert 1GB
Print out all your environment variables and see what they contain. Maybe it's a casing problem.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -wT
  2. # Print a formatted listof all the environment variables
  3.  
  4. use strict;
  5.  
  6. print "Content-type: text/html\n\n";
  7.  
  8. foreach my $key (sort keys %ENV) {
  9.     print "<p><b>$key</b><br>";
  10.     print $ENV{$key};
  11. }
  12.  
- Miller
Sep 6 '07 #2
patelxxx
135 100+
All the environmental variables are printing as normal such as Homepath, processor_identifier, OS etc.

However there is no 'HTTP_USER_AGENT' in the list of Environmental variables.
Sep 7 '07 #3
numberwhun
3,509 Expert Mod 2GB
I can vouch that it doesn't print that variable on my Windows machine or my Solaris box either. I think that this script needs to be run through Apache to get that environment variable. Actually, do you have Apache running on this system? It would probably set that variable.

Regards,

Jeff
Sep 7 '07 #4
patelxxx
135 100+
I have Apache is running successfully and still I get the problem.
Sep 7 '07 #5
numberwhun
3,509 Expert Mod 2GB
It may be that this script would need to be run via a web page to determine what browser is accessing the site. It may not be something that works via the command line. (Yes, I am just speculating here, considering the variable is not set).

Regards,

Jeff
Sep 7 '07 #6
patelxxx
135 100+
Resolved now, the problem was due to the Shebang line not pointing to the perl.exe and also I didn't know the URL to run the script locally, the URL to run the script locally is: http://localhost/cgi-bin/browser.cgi

Thanks Numberwhun for your help.

Cheers
Sep 12 '07 #7
numberwhun
3,509 Expert Mod 2GB
Your welcome, glad we could all help.

Regards,

Jeff
Sep 12 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: deko | last post by:
Can someone point me to a sample script that will log all visitors to my web site? I'm looking for a simple script that will capture IP address, Host Name, Browser, OS, and referring page - and...
2
by: Will | last post by:
How would you translate the following script into something that would work with register globals set to 'off'? --- $envs = array("HTTP_REFERER", "HTTP_USER_AGENT", "REMOTE_ADDR",...
4
by: Daniel Orner | last post by:
Does anyone know of a simple way to have a Python script find out what browser is accessing it? After a web search the only thing I found to do this is Zope, but the system I'm programming doesn't...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
6
by: Lorna | last post by:
I can't seem to get the ENV variable HTTP_REFERER when posting with CGI from one program to another. In my post program I have put in the <HEAD> HTTP_REFERER =my host - ie www.xyz.com (I have...
0
by: gervo | last post by:
I have built a series of email forms in flash MX. using perl. the forms work for some people but not all and I was hoping some one could help me out. Here is the Actionscript on the send button ...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
4
by: alag20 | last post by:
Hi Guys, Sorry for duplicate posting as this Question refers to both c# and perl cgi script on the net, so please help. Here is the original post...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.