Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help scripting a CGI script

         

J_n_b

6:26 pm on Sep 22, 2006 (gmt 0)

10+ Year Member



I am trying to insert a piece of JavaScript in a CGIProxy script, im sure some of you are fimiliar with it. When i enter it right in, and upload it is just a blank page when i try to browse (it works fine without the javascript in it).
Any ideas how i do it?

rocknbil

6:37 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



More info required! :-)

Chances are it is actually erroring in mid-script. Many coders like to put

print "content-type: text/html\n\n";

right at the beginning of the script. The reason for this is whenever they are wrangling with a problem, they can issue a print command anywhere in the program and it won't server error.

The downside is this - if the script errors and prints something to STDOUT, it doesn't necessarily print to the browser. So you get a blank page, no server 500, no indication of the problem.

Without seeing your code, there are several things you need to consider when adding Javascript. The most obvious is the use of \n because \n serves the same function in perl as in Javascript. So if you have Javascript code like this,

$js = "var msg = 'The email field is blank.\n Please fill in the email field.';";

You need to use \\n to make sure it gets to the browser as \n.

The other and more dangerous problem is the use of the unbroken pipe (¦ <-- this will show as a broken pipe on this board, I am referring to the unbroken one.) In Javascript and perl this means a logical OR, but if incorrectly coded it can be interpreted by perl as an actual pipe command, which means to pipe data or other output to a program.

This should arm you with enough info to begin looking at your script and find the problem, but if you can't figure it out . . .

Post your code!

:-)

simon2263

8:34 am on Sep 30, 2006 (gmt 0)

10+ Year Member



If you have it installed, try also using

use CGI::Carp qw(fatalsToBrowser);

at the top of your program. This will print any error messages to the browser (they usually get lost because the browser only sees what gets printed to standard output - STDOUT -, whereas errors go to standard error - STDERR).

Simon

perl_diver

8:43 pm on Sep 30, 2006 (gmt 0)

10+ Year Member



errors generally go to the error log. Using CGI::Carp is a good tool for debugging CGI scripts, especially if you can't read the error log for some reason.