Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 18th, 2006, 2:14 AM   #1
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
n00b question

here is the html file:

it takes your name.

<HTML>
<HEAD>
<TITLE>Ben's CGI Test Page</TITLE>
</HEAD>
<BODY text = "aqua" bgcolor = "black">

<BASEFONT SIZE = 4>

<h1 ALIGN = "center">Ben's CGI Test Page</h1>

<hr WIDTH = 75% ALIGN = "center" size = "8">

<p>What is your name?</p>
<form METHOD = "POST" ACTION="http://cgi-bin/test.cgi">
<input type = "text" NAME = "username" SIZE = 40 MAXLENGTH = 40 VALUE = "your name here">

<p><input type="submit" value ="send data"> &nbsp&nbsp&nbsp&nbsp <input type = "reset" value = "clear"></p>

</form>

</BODY>
</HTML>

here is the perl source:

it prints out "hello" + whatever you entered...in theory.

use CGI ' :standard';

$input = param('username');

print "Content-type: text/html \n\n";
print "hello $input";

i'm using the sambar server to test the crap locally, http://localhost/page1.html is the html file on the server.

the main directory is c:\Program Files\sambar63

under that we have the following:

the html file is actually located in a subdirectory called "docs".

the perl file is in the cgi-bin directory.

i think i'm fucking this up from putting things in the wrong place or not looking for the right place. also, what's the difference between saving the perl file as as *.pl as opposed to *.cgi ?

when i click to submit the name i get sent to the us government census page...WTF!?!
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old May 18th, 2006, 2:36 AM   #2
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
If you are getting sent to the US goverment census page, well I don't know why, but that is strange. Although one thing I noticed was the action says:

http://cgi-bin/test.cgi

Shouldn't it be -

cgi-bin/test.cgi
??

If it has http://, doesn't it point to a remote location, not back to yoru server? It's the only thing I can think of, and might explain the bizaare gov page problem. I've never used Sambar, I like Abyss (http://www.aprelium.com/). It's really easy and great for testing/development stuff. Also has perl support w/ tutorial.

The difference between *.cgi, and *.pl:

I'm not quite sure, don't think it really matters. The only thign that does matter is the way the server views them. The server has to be set up to see *.cgi or *.pl. Hell I think you could call it *.whocares , just long as the server is set to look for that type. I've never worked with a whole lot of perl, but the only other thing that comes to mind is the first line. I always thought the first line of a .pl file was supposed to point to the cgi-bin or where ever the perl interpreter was. is that what your 'use' line does? Sorry, I've never donme it with a *.cgi extension before.

Sorry I can't be of more help. Hope this helped a little though
Booooze is offline   Reply With Quote
Old May 18th, 2006, 2:46 AM   #3
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
i'll try tomorrow, i know my free perl ide bitches about using the cgi functions if i don't save it as a cgi file.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old May 19th, 2006, 2:07 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
well, tried a billion variants, looking at the sambar docs now...
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Jul 12th, 2006, 4:43 PM   #5
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 321
Rep Power: 4 mackenga is on a distinguished road
http://cgi-bin/test.cgi is looking for /test.cgi on a host called cgi-bin. nslookup tells me that doesn't exist but Firefox on my machine also sends me to the US Census site. Weirdness! I tried the obvious url mangling tricks some browsers will do to try to guess the URL but I didn't hammer away at it long; suffice it to say cgi-bin.com, www.cgi-bin.com etc. don't point to the US census site so it's still a mystery why we're getting forwarded there.

But as Booooze points out, you don't want the http:// at the start; you seem to be trying to refer to what's known as the 'relative URL' to your CGI script. You can use cgi-bin/test.cgi as Booooze suggests; this assumes cgi-bin is a subdirectory of the directory your starting point is in, or at least that it looks like it is from the outside of your webserver (in many cases, as on my webserver, the real layout is a little different and cgi-bin is not really under the document root). If you always want to point to a cgi-bin in the 'root' of your webserver, just use /cgi-bin/test.cgi. Alternatively, you can use http://localhost/cgi-bin/test.cgi (here, localhost is your machine, or more precisely the name of the loopback interface). You can even use your machine's actual name in here; on my box here I can do: http://vulture/cgi-bin/test.cgi (except that test.cgi doesn't exist of course).

Anyway...other than this, there is a minor problem in your Perl code:

Content-type: text/html \n\n

I notice a space before the first backslash; generally this shouldn't affect anything but you don't need it and you never know. Second, \n\n sends two 'newlines' - if something between you and the browser is going to do end-of-line translations to fix this or if the browser is tolerant then all is well, but technically \n\n is newline newline and the correct terminator here is \015\012\015\012 (octal escapes for carriage return, line feed, carriage return, line feed). For some reason usually lines are separated by that two-char combination out there on the web (and in certain bizarre, obscure and archaic operating systems, like VMS and, ah, what's the other one? Ah yes, Windows I think it was called, but I don't think anyone uses it any more... )
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Old Jul 12th, 2006, 4:57 PM   #6
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
Try adding the path to the perl executable at the top of the file I think its somehting like ##!C:\Perl\bin\perl except that is my path you should use your own.
Wizard1988 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC