michellem has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks,

I've got a very strange problem. I'm working on a database search application - it's based on a foundation I've written and debugged for a while now. I have a very wierd problem: I've got basic database output which has a header row, and then rows for individual records. The header row is hotlinked so you can sort the output by that field. The first column values of the records are hotlinked to send you to see the full record. This has worked fine for a while. I've moved the script to a new server, and the links result in an internal server error. However, when I manually type in the same information into my browser, it works fine! (the links look like: http://www.somewhere.com/cgi-bin/whatever.cgi?output=list&sort=user - or similar)

I'd use the error logs to debug, except on this server I can't get access to them. There are no syntax errors or warnings. The same exact script on a different server works fine.

Suggestions? (for info, and to head off possible questions: yes I'm using CGI, yes I'm using perl -w and strict.)

Replies are listed 'Best First'.
(Ovid) Re: Very wierd CGI behavior
by Ovid (Cardinal) on Nov 29, 2001 at 02:39 UTC

    Try putting this at the top of your code.

    #!/usr/bin/perl -wT # ensure all fatals go to browser during debugging and set-up # comment this BEGIN block out on production code for security BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); }

    If you can type in the URL and it works, it means your script is doing okay. Can you show us the HTML? Poorly formatted HTML could cause issues. Any chance that you have a base HREF set up in the HTML document that's forcing the links to another domain?

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Very wierd CGI behavior
by cLive ;-) (Prior) on Nov 29, 2001 at 03:03 UTC
    First, check the obvious:
    • type the link in manually, copy it and paste to a text editor
    • right click on link that fails and copy 'Link Location'/'Shortcut' or whatever your browser calls it. Paste this in the text editor underneath the other link.
    If they are the same, the only thing i can think of is if your script performs some action based on the $ENV{'HTTP_REFERER'} environment variable, and when a referer exists, the script dies nastily at some point.

    So have a play, use CGI::Carp and see what happens...

    cLive ;-)

Re: Very wierd CGI behavior
by runrig (Abbot) on Nov 29, 2001 at 02:41 UTC
    Are you using CGI::Carp's fatalsToBrowser, and printing a valid header as soon as possible (so the error message is sure to come after a header)?