0

I'm making a logging script that will log a visitor's way through the website. For example, it would write to a log file:

[Username (if logged in)]-[IP] requested [Page] at [Time]--received [Error Code] [Error Code Description].

Example output:

Jaxo (127.0.0.1) accessed index.php at 2:05 PM--Received 200 Ok

I can get everything working except the error codes bit (the part after the --).

How can I get error codes and error code definitions from PHP?

Thanks!

1
  • A bit off topic, but if you logged just the username and IP you could map it against the server error and access logs rather that duplicating them. If you have control of your webserver setup, or have a nice admin, you can set things up so that your website logs separately from the others on the server. Commented Mar 16, 2011 at 18:19

2 Answers 2

3

These error codes(200, 404 etc) are generated by your webserver, for example Apache. A way that you can trap these errors is to send these errors to another php script in your .htaccess file, for example.

ErrorDocument 404 /error.php?error=404
ErrorDocument 500 /error.php?error=500
ErrorDocument 402 /error.php?error=402

etc.

Unfortunately you can't have a "catch all" ErrorDocument, so you need to list them one by one.

Sign up to request clarification or add additional context in comments.

Comments

0

Error codes about what? Are you thinking about HTTP status codes?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.