We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Why is the browser prompting to download my cgi file?

deeayrian asked
Medium Priority
Last Modified: 2013-12-25
I have created a main html page that has a image link on it.  When I click on the image, it is supposed to take me to my login.cgi file which is a very basic login form using cookies.  However, when I click on the image, the browser actually shows a pop up window and asks me if I want to open, save or cancel the login.cgi file.  I have confirmed that my cgi file is in the cgi-bin folder and the permissions are set to 755.  I have also confirmed that the path is correct to my login.cgi file.  

Does anyone know why it is doing this?
Watch Question


Are you using php asp.. never minds you have to set your pc to be a server hosting php or asp
after that you have to run your site through your local host.

You see when you turn the pc into a server you have to set a root directory for web so any requests on port 80 are directed to this directory, and right there your file should be stored and you can go there by pointing your browser to http://localhost. example : http://localhost/test/myloginscript.php
where my file is stored as such:  c:\www\test\loginscript.php where www is set as root directory.

There are a lot of ways to turn your pc into a server one of which is download and install xampp look it up in google


I am sorry, I forgot to specify that this is for a school assignment and my file is on a unix server.  Therefore the path specified is: https://crux.baker.edu/~dvelas01/cgi-bin/.....(the rest of my path)
I created another cgi file in the same exact directory as my login.cgi file and it worked just fine.  Both have 755 permissions and both were accessed from the same main html file (I just changed the name in the path to test it).

I see, could you try renaming your first cgi file that worked with some backup name and then rename this one that is not working with the frist one's name, so we can see if then it works?


good idea.  But it didn't work.  
I also renamed the non-working file to login1.cgi and changed the path to open login1.cgi and it didn't work.  
I am using pico to manage the document so I don't know how to paste the code into here from there.
Any other ideas?

What I think you need to do is download files to your pc check file names check code, pate anything you like from here to there then upload them to the server and set permissions and then try again.
Now from admin point of view all cgi files in your account could be set to execute or your admin could have allowed only one specific filename to be excuted.

Could you paste your code for the login script here so I can more understand what is going on here!?


I really do not think this is an admin issue.  I have been doing assignments on this system for 6 weeks with no problems.  I was able to obtain my code for you.  It is posted below.  
#login.cgi - allows user to login to site using cookies
print "Content-type: txt/html\n\n";
use CGI qw(:standard -debug);
#prevent Perl from creating undeclared variables
use strict;
#declare variables
my $username;
#retrieve Name cookie
print <<htmlprint;
<title>American Idol Voting Contest</title>
<style type="text/css">
body {background-color: black}
td {font: arial, white}
h1 {font: arial, white}
<h1><center>Type your name below and hit submit to enter our website</center><h1>
<FORM ACTION='https://crux.baker.edu/~dvelas01/cgi-bin/finalproject/votes.cgi' METHOD=POST>
<tr><td>Full Name:</td><td><input type=text Name=Name SIZE=30 
<tr><td><input type=submit Value=Enter Site></td></tr>

Open in new window


one other I can also think of is to check the file encoding.
Meaning try and paste the code into new notepad doc, then save as, make sure to choose all files and then ANSI and once done with it try uploading it and then set permission and try to run.

Another thing I hope you are trying to execute it from your pc using IE for example and not from the server.
Top Expert 2009
The content type should be "text/html", not "txt/html".  Also, you should be using the CGI module to send your header - you do not have a property formatted header the way you have it.

#login.cgi - allows user to login to site using cookies
use CGI qw(:standard -debug);
print header();  #Default content type is text/html
use strict;

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


The missing e in the word text is what was causing the problems.  Thank you very much.  As far as the header goes, the way I have it is not a problem.  It is the way we are taught to do it from our book and it works fine the way it is.  Thank you very much for catching the "e".  I looked over the code dozens of times but these tired eyes needed a second set.  
Top Expert 2007

Sounds like your book is not a very good reference.  What's the name of it?
Top Expert 2009

I agree with Tintin - the book is teaching you to send an incorrect header.  Most (all?) browsers will work with the incorrect header anyways, but still, you should be doing it correctly.

Each header is supposed to end with the sequence: character 13, character 10.  Then at the end of all headers, an additional character 13, character 10 sequence.

The header function from the CGI module handles this.  

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.