Getting status/response codes in Perl

A

Ali

Hi,

I've created a site and on one page I need to print certain
information out to a log file. I've managed to get all the data that
is required except a 'HTTP response code'. I've searched through
several books and websites and all I've come up with is that they are
also called status codes and I've found how to create a page that is
displayed when a certain status code is found but I can't find out how
to log the status of the page that was loaded.

Does anyone know how to do this and am I right in saying that for the
page to have loaded correctly the code must be 200?

I thought it might be stored as an environment variable like when
setting and retrieving cookies but I can't find any environment
variables associated with status codes.

Can anyone help?

Thanks very much,
Ali :eek:)
 
G

gnari

I've created a site and on one page I need to print certain
information out to a log file. I've managed to get all the data that
is required except a 'HTTP response code'. I've searched through
several books and websites and all I've come up with is that they are
also called status codes and I've found how to create a page that is
displayed when a certain status code is found but I can't find out how
to log the status of the page that was loaded.

Does anyone know how to do this and am I right in saying that for the
page to have loaded correctly the code must be 200?

I thought it might be stored as an environment variable like when
setting and retrieving cookies but I can't find any environment
variables associated with status codes.

not really a perl question, but in general the web server does decide
what the status code is until the cgi script has finished, because if
the said script should terminate with error, a status 500 is returned.

you must either
a) assume there will be no error,and log code 200, preferably as the very
last action your script does
or
b) retrieve the status code from the webservers log file and join that
somehow with your logfile
or
c) your webserver may allow for your application to add information
to the webserver logfile. (Apache+mod_perl, for example allows this)

gnari
 
A

Ali

Thanks very much, that was extremely helpful. I think I know what I have to do now!

Ali :eek:)
 
G

gnari

Ali said:
Thanks very much, that was extremely helpful. I think I know what I have to do now!
that's good, but there is no need to quote the whole article you are
following up on. rather quote the relevant bits, and add your response
after it. That makes it so much more readable, specially if it develops
into a real thread.
"gnari" <[email protected]> wrote in message
[snipped whole quoted article]

gnari
 
P

pkent

also called status codes and I've found how to create a page that is
displayed when a certain status code is found but I can't find out how
to log the status of the page that was loaded.

If you're using Apache then the default access log format includes the
status code - so it's already being logged, albeit in a separate file.

am I right in saying that for the
page to have loaded correctly the code must be 200?

No, the web server can return a valid response with some content with a
number of response codes.

I thought it might be stored as an environment variable like when
setting and retrieving cookies but I can't find any environment
variables associated with status codes.

The response code is, AFAICT, decided on by the web server, not the CGI
application (except in NPH mode). But if you want to explain in a bit
more detail what you're trying to achieve then maybe I can be of a bit
more help

P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top