Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI Newbie, come and laugh at my question!! 1

Status
Not open for further replies.

mckarl

Programmer
May 5, 1999
147
0
0
GB
Visit site
oki doki everyone!!  (is it me or has andybo been the helpfullest person on tek-tips since ever)<br><br>i am trying to learn to CGI script, using perl. (cos if i was using anything else, activeperl wouldnt work now would it :) )<br><br>i got my HTML:<br>------------------------------------------------------------<br>&lt;HTML&gt;<br>&lt;TITLE&gt; -- Name CGI script -- &lt;/TITLE&gt;<br><br>&lt;BODY&gt; <br>&lt;P&gt; Welcome to my name CGI script. &lt;/P&gt;<br>&lt;P&gt; Please Enter your name and other details in the prompts below, click submit when you have entered your details, or reset to clear. &lt;/P&gt;<br><br>&lt;FORM METHOD=POST ACTION=&quot;details.cgi&quot;&gt;<br>&lt;PRE&gt;<br>firstname &lt;INPUT TYPE=&quot;text&quot; NAME=&quot;fname&quot; MAXLENGTH=15 SIZE=15&gt;<br>surname   &lt;INPUT TYPE=&quot;text&quot; NAME=&quot;sname&quot; MAXLENGTH=15 SIZE=15&gt;<br>email add &lt;INPUT TYPE=&quot;text&quot; NAME=&quot;email&quot; MAXLENGTH=35 SIZE=35&gt;<br>&lt;INPUT TYPE=&quot;submit&quot; VALUE=&quot;Send Mail&quot;&gt;<br>&lt;INPUT TYPE=&quot;reset&quot;  VALUE=&quot;Clear Details&quot;<br>&lt;/PRE&gt;<br>&lt;/FORM&gt;<br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br><br>============================================================<br><br>and her's my Perl code:<br><br>------------------------------------------------------------<br><br>read(STDIN,$temp,$ENV{'CONSTANT_LENGTH'});<br>@pairs=split(/&/,$temp);<br>foreach $item(@pairs)<br>{<br>($key,$constant)=split(/=/,$item,2);<br>$content=~tr/+/ /;<br>$content=~s/%(..)/pack(&quot;c&quot;,hex($1))/ge;<br>$fields{$key}=$content;<br>}<br><br>print &quot;Content-type: text/html\n\n&quot;;<br>print &quot;&lt;HTML&gt;\n;<br>print &quot;&lt;BODY BGCOLOR=#FFFFFF&gt;\n&quot;;<br>print &quot;&lt;CENTER&gt;\n&quot;;<br>print &quot;Thank you &lt;BR&gt;\n&quot;;<br>print &quot;$fields{fname} $fields{lname}&lt;/BR&gt;&quot;;<br>print &quot;I will write&lt;BR&gt;\n&quot;;<br>print &quot;you at &lt;BR&gt;\n&quot;;<br>print &quot;&lt;/CENTRE&gt;\n&quot;;<br>print &quot;&lt;/BODY&gt;&lt;/HTML&gt;&quot;;<br><br>============================================================<br><br>now, as i said before, here are the stats:<br>     o   Windows NT Workstation<br>     o   Active Perl<br>     o   I'm thick<br><br>but i have a real big probz. how can i compile a .pl script into a cgi script, without it trying to download it all the time?<br><br>Please help, like i said, i'm just starting up on this whole cgi thingy wotsit so it'll probably sound really silly. <br><br>Thanks to everyone who replies, and those who look at and think i'm insane, and decide not to answer me.<br><br><br>Many thanks again. Karl. <p> Karl<br><a href=mailto:mc_karl@yahoo.com>mc_karl@yahoo.com</a><br><a href= > </a><br> ~ ~ ~ ~<br>
K A R L<br>
~ ~ ~ ~
 
just a guess -- sounds like you may be using IIS web server.....<br><br>If you are getting the text of the program returned to your browser rather than having the program execute and produce the desired page, then, I think, your web server does not recognize your cgi script as an executable.&nbsp;&nbsp;I am much more familiar with Apache ( sounds like you may be using IIS)......but, a plain vanilla Apache set up has specific directories where cgi scripts can live and function.&nbsp;&nbsp;Typically,....<br>your static html would be in something like <FONT FACE=monospace>/httpd/htdocs/</font><br>and<br>your cgi code would be in something like <FONT FACE=monospace>/httpd/cgi-bin/</font>.... <br>With Apache you can specify 'Script Alias' dirs to allow cgi execution in dirs other than the default cgi-bin.&nbsp;&nbsp;If a piece of code is in any dir other than the ones the server thinks are <font color=red>cgi</font> dirs, then it treats the file as a text file and does not execute it.&nbsp;&nbsp;There must be some similar control when using IIS.<br><br>'Hope this helps. <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
cheers boaterdude, <br><br>yeah, i diddnt even know i needed an IIS, (or i would have put it down), however, i'm sorting things out now :)<br><br><br>Thanks!!<br><br>Karl. <p> Karl<br><a href=mailto:mc_karl@yahoo.com>mc_karl@yahoo.com</a><br><a href= > </a><br> ~ ~ ~ ~<br>
K A R L<br>
~ ~ ~ ~
 
ok everyone, i sorted things out now, (kinda), i have put my web CGI wotsit on my linux (Rh6) box, and am trying to get round it this way. <br><br>Everything runs great!! -- but when i click submit, it doesnt. doesnt move, just sits there, waiting, waiting for something... zzZZZZ ...<br><br>How can i test if apache is running? -- and what the heck is wrong with it??&nbsp;&nbsp;&nbsp;anyone??&nbsp;&nbsp;ppplleeeassseeee..<br><br>T h a n k s&nbsp;&nbsp;&nbsp;f o r&nbsp;&nbsp;&nbsp;a n y&nbsp;&nbsp;&nbsp;h e l p&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;m e d i c a l&nbsp;&nbsp;&nbsp;a d v i c e <br><br>Karl.<br><br>(I still agree we try and oust AndyBo for that jacket!! -- i will laught if he dont get it, cos he's been up there forever at the moment!!) <p> Karl<br><a href=mailto:mc_karl@yahoo.com>mc_karl@yahoo.com</a><br><a href= > </a><br> ~ ~ ~ ~<br>
K A R L<br>
~ ~ ~ ~
 
Let's make CGI as simple as possible and go from there.....<br>Copy the following chunk into your '/cgi-bin/' directory.&nbsp;&nbsp;Once we are sure that Apache is doing its job, we'll figure out why the other code is not working.<br><br><FONT FACE=monospace><br>#!/usr/local/bin/perl </font><font color=red>change to point at your Perl install and delete this red stuff</font><FONT FACE=monospace><br>print &quot;Content-type:&nbsp;&nbsp;text/html\n\n&quot;;<br>print &lt;&lt;EndPrint;<br>&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;JUNK&lt;/TITLE&gt;&lt;/HEAD&gt;<br>&lt;BODY&gt;<br>&lt;P&gt;CGI RAN&lt;/P&gt;<br>&lt;/BODY&gt;&lt;/HTML&gt;<br>EndPrint<br></font><br><br>Modify the top line, if necessary, to point at your Perl.<br>Do - &quot;chmod +x filename&quot; where filename is your file to make the script executable.<br>Open a browser and go to that file via the path that contains your cgi-bin directory.<br>If your cgi-bin is '/httpd/cgi-bin/' and you named your file 'simple.cgi',&nbsp;&nbsp;<A HREF=" TARGET="_new"> should see 'CGI RAN'.<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
ok boaterdude, booted up my linux, and i have three cgi-bin's.<br><br>here are the locations...<br><br>/tmp/apache/cgi-bin<br>/tmp/apache/cgi-bin/usr/tux... /webgui/cgi-bin<br>/usr/lib/cgi-bin<br><br>i will try the code into each or the directories, and try them... (By the way, i'm typing this as i go along :))<br><br><br>ok, firstly /usr/lib/cgi-bin (the one i would think most likely)<br><br>1. I needed admin privs for the writing of the cgi script.<br>2. wrote the code and chmod'd it.<br>3. launched it into netscape (using <font color=red>netscape testcgi.cgi</font>)<br>4. watched it print everything i just entered into the file in netscpae (including #!/usr/lib/perl)<br>5. Perled the version, found some code to be incorrect (or newwer than my version of perl)<br>6. changed the &lt;&lt; to all print statements.<br>7. Relaunched netscape (after checking it worked)<br>8. failed (only showed the code again)<br>9-55. tried every type of re-direct, piping, everything through netscape. -- either same or no result.<br>56. Made a brew.<br>57. thought about learning java instead :)<br>58. Signing off, waiting for some more help from you :)))<br><br>-- By the way, sorry it took so long, moved house last few days, had no computer access (aarrghhh) and no internet.<br><br>Thanks very much, <br><br>Karl..<br><br><br> <p> Karl<br><a href=mailto:mc_karl@yahoo.com>mc_karl@yahoo.com</a><br><a href= > </a><br> ~ ~ ~ ~<br>
K A R L<br>
~ ~ ~ ~
 
There are not many things that will keep this from working........<br><br>1 - Perl syntax - sounds like you have that one handled.<br>2 - Execute bit is set '-rwxr-xr-x'.&nbsp;&nbsp;- sounds like you have that one handled.<br>3 - trying to do something in the Perl code that the httpd daemon does not sufficient <br>&nbsp;&nbsp;&nbsp;&nbsp;priviledges to do.&nbsp;&nbsp;This will make the code crash.&nbsp;&nbsp;You would get an error, not the text of your code.<br>4 - web server is running - will it serve static pages?<br>5 - web server configuration - ?????<br>You should have a server config file, 'http.conf', which controls the behavior of your web server. In that file, there is a specification for ,ScriptAlias, the location of you cgi-bin dir.<br>Plain vanilla will look like this.<br><FONT FACE=monospace>ScriptAlias&nbsp;&nbsp;&nbsp;&nbsp;/cgi-bin/&nbsp;&nbsp;&nbsp;&nbsp;&quot;/httpd/cgi-bin/&quot;</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;your cgi-bin <br>That is where your Perl/CGI code should reside.&nbsp;&nbsp;That is your <i>cgi-bin</i>.&nbsp;&nbsp;You should be able to save the code listed previously as a file in that dir, chmod it,&nbsp;&nbsp;and then run it via the browser.&nbsp;&nbsp;We have to be getting close.<br><br>'hope this helps.<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
waw, sorry it took so long to reply, i have been very busy moving house and such, and wasnt feeling too well last couple of days, <br><br>Ok, i'm shutting windows down, and seeing what my vinilla thingywotsit says..<br><br>Over.<br><br>Karl. <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
well, can't find a http.conf file nor can i find a httpd directory...<br><br>Is there any way of directly testing if apache is up and running/setup to run??<br><br>maybe i should try re-installing apache, hhmm... i got the RH 5.1 disk, i'll see if i can re-install apache in my 6.1.<br><br>Oki doki, booting back up to linux, <br><br>zzzzzzoooooooooooooooommmmmmm<br><br>Karl. <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
sorry - the config file is 'httpd.conf'.&nbsp;&nbsp;I left the '<font color=red>d</font>' out previously.<br><br>To see if the server is running......<br><br>You should be able to bring up a browser on the machine that is running Apache and go to the URL, <i>localhost</i> or <i>127.0.0.1</i>.&nbsp;&nbsp;If Apache is up, you should get the default 'Welcome to Apache' index.html page.<br><br>If that does not work, you can check to see if there is a process running that looks like the web server daemon (httpd).&nbsp;&nbsp;There should be one or more. <br><i>ps -ef ¦grep httpd</i> <br>I'm running Solaris.&nbsp;&nbsp;The '-ef' switches might be different on RH.&nbsp;&nbsp;See the man page for 'ps', if need be.&nbsp;&nbsp;That will give you a list of the processes on your machine which look like the web server daemon (httpd).&nbsp;&nbsp;One of them should have the same process ID as that found in your 'httpd.pid' file which Apache writes when it starts.&nbsp;&nbsp;That is your web server process.&nbsp;&nbsp;If you did not get the 'Welcome' page and there is a process that looks like 'httpd', then you don't have things quite write in your 'httpd.conf' file.&nbsp;&nbsp;<br><br>Some servers are setup to use inetd to start the server each time a request is received by inetd.&nbsp;&nbsp;In that case you would not have a continously running web server process.&nbsp;&nbsp;You would have to configure the server to run that way.&nbsp;&nbsp;I doubt you&nbsp;&nbsp;are doing that.&nbsp;&nbsp;That is not Apache's default behavior, I don't think.<br><br>' hope this helps.&nbsp;&nbsp;<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Boaterdude!!<br><br>Well, here's what i did today...<br><br>After repeatedly &quot;WhackinG&quot; my pc almost to death, i decided it was time for a change. so i 'upgraded' from my RH6.2 to my RH5.1 and continued to kick the C%A% out of it until i decided it wasnt helping. <br>When my foot was bandaged, i completed my 5.1 installation, and installed everything wonderfuly. <br>Then i loaded up my xwindows, and it crashed. &quot;Several times&quot;.<br>Meanwhile, my 5th installation was going well, and my bandage practice is so good i thought of becoming a nurse;<br>and i got everything loaded. 16 Colours in my 4mb ATI Rage IIc (what's it called again?-optimising?) --anyhow, so i got it sorted, inserted the perl script, all was well, and then i ran it. *SCREAM* it did the same thing, and with both my legs bandaged up, i began repeatedly hitting it with the front of my skull, at this point, mark came across (just been on holiday in canada) and told me rather than trying to access it through the standard filesystem:<br><br>file:/home/httpd/cgi-bin/test.cgi<br><br>Access it as:<br><br><A HREF=" TARGET="_new"> at this point, the heavens opened... and began to rain heavilly over here is &quot;sunny&quot; england, but i diddnt care cos it <b>WORKED!</b>.<br><br>Now, i'm gonna format it again (hey why not?) and put mandrake in there, (along with my faithful(hahahaha??) windows nt).<br><br>Thankyou Boating, you have enlightened me further that simpleton, i have learned from you that all my cgi programs needed to be executable (something easily forgettable) that i needed apache/IIS (depending on the OS) and MANY other things.<br><br>Thankyou once again,now i'm Mr. CGI!!!<br><br>(<b>C</b>ommon <b>G</b>it <i>from</i> <b>I</b>ngland!)<br><br>-no, really, thanks! ... no doubt i will be writing asking for your help in the <i>very</i> near future!!&nbsp;&nbsp;:)<br><br>C-U soon!!!!!&nbsp;&nbsp;<br><br>Karl.<br><br><br><br><br> <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top