473,656 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to print $ENV{'HTTP_USER _AGENT'} ?

135 New Member
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 4153
miller
1,089 Recognized Expert Top Contributor
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 New Member
All the environmental variables are printing as normal such as Homepath, processor_ident ifier, OS etc.

However there is no 'HTTP_USER_AGEN T' in the list of Environmental variables.
Sep 7 '07 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
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 New Member
I have Apache is running successfully and still I get the problem.
Sep 7 '07 #5
numberwhun
3,509 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator Specialist
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
6734
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 write that info to MySql. I've created a MySql database - visitors - with the columns mentioned above, but am fumbling trying to get started with PHP... any help is appreciated!
2
1706
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", "REMOTE_HOST", "QUERY_STRING", "PATH_INFO"); foreach($envs as $env) { if(isset($$env))
4
14195
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 use Zope and I'm not really interested in installing it just for this minor detail. Is there another way? Thanks! --Daniel Orner
6
4866
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
6
5349
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 also tried removing it entirely in case that was causing problems. I have tried to extract the HTTP_REFERER in my receiving program with $http_ref = $ENV{'HTTP_REFERER'}; That didn't work so I just printed all variables with foreach $key...
0
2031
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 on (release, keyPress "<Enter>") { if (company ne "" and first ne "" and last ne "" and phone ne "" and fax ne "" and mobile ne "" and email ne "" and address ne "" and city ne "" and state ne "" and zip ne "") { i = "0"; validmail = 0;...
1
47441
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
4
3076
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 http://bytes.com/topic/c-sharp/answers/870412-internet-logging-using-c-perl-cgi-script#post3493381 which contains the perl cgi script and c# code i am using. Please help - any help will be highly appreciated.
0
8296
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.