سؤال

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!

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top