PHP Logging Question - Error Codes - php

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?

Related

Default Error Page PHP 500 errors in Apache [duplicate]

As a prelude, I know what a HTTP 500 is, and I know how to fix them.
On PHP 5.3, i'm running a production environment with show_errors off. When there are any fatal errors, the user gets a plain white 500 page in response. I'm trying to create a 500 error page just in case there any any errors; just so it is more user friendly.
I used to be able to do
ErrorDocument 500 500.html
It doesn't seem to be working anymore, however - even thought my 404
ErrorDocument 404 404.html
Works fine.
Curious to see solutions regarding this -
Thank you for your time.
Fatal errors don't produce 500 errors in and of themselves, they would return 200 with blank page typically (if no output had been flushed to browser at the point of the error) . Plus this will not help you anyway, as Apache would be no longer involved when PHP is having the error.
Maybe you could register a shutdown function to send 500 header (to get 500 result) and display the content you want to display.

Tracking log file for error in CI

In my codeigniter application I am repeatedly getting this error message in log files.
ERROR - 2016-06-10 00:15:19 --> 404 Page Not Found: /index
How to know what is causing this error, as me and my team have ran through whole website multiple times and didnt found it.
Somewhere in your application you're hitting /index ( eg. www.example.com/index) .. but you don't have a controller named Index.php defined. Thus resulting in 404 Page Not Found.
You don't have a route defined as index, or you don't have a controller defined as Index. A 404 Error is exactly that. The page wasn't found.
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No
indication is given of whether the condition is temporary or
permanent.
If the server does not wish to make this information available to the
client, the status code 403 (Forbidden) can be used instead. The 410
(Gone) status code SHOULD be used if the server knows, through some
internally configurable mechanism, that an old resource is permanently
unavailable and has no forwarding address.

Joomla 2.5 404 issues

I have a J2.5site set up that uses language. Thus the urls look something like this:
https://www.mysite.com/en/
and
https://www.mysite.com/en/my-component/
and
https://www.mysite.com/en/my-component/my-alias
I have also set up a script that emails me whenever a 404 or 500 etc occurs:
Here is the result of one (of hundreds):
500 - Error: 500
Invalid controller: name='index', format=''
Call stack
Function Location
1 JSite->dispatch() /opt/host/apps/joomla/htdocs/index.php:42
2 JError::raiseError() /opt/host/apps/joomla/htdocs/includes/application.php:208
3 JError::raise() /opt/host/apps/joomla/htdocs/libraries/joomla/error/error.php:251
URL:/en/index.php
Notice the request. If I understand correctly, nothing should ever ask for /en/index.php. since by that time, it has already been interpreted by the entry index.php and therefore appends '/en/'
I am not getting any request errors in my apache logs or any other apache errors.
All that is happening is that I am being bombarded with emails stating that something tried to access http://www.mysite.com/en/index.php or https://www.mysite.com/en/my-component/index.php and thus either generated a 404 or 500 error
Is this spider (search engine bot) issues or is it a server misconfiguration?
Thanks
Jacques

PHP: 500 Error to error page

As a prelude, I know what a HTTP 500 is, and I know how to fix them.
On PHP 5.3, i'm running a production environment with show_errors off. When there are any fatal errors, the user gets a plain white 500 page in response. I'm trying to create a 500 error page just in case there any any errors; just so it is more user friendly.
I used to be able to do
ErrorDocument 500 500.html
It doesn't seem to be working anymore, however - even thought my 404
ErrorDocument 404 404.html
Works fine.
Curious to see solutions regarding this -
Thank you for your time.
Fatal errors don't produce 500 errors in and of themselves, they would return 200 with blank page typically (if no output had been flushed to browser at the point of the error) . Plus this will not help you anyway, as Apache would be no longer involved when PHP is having the error.
Maybe you could register a shutdown function to send 500 header (to get 500 result) and display the content you want to display.

how to know if my users got a 500 Error?

my boss says "when I try to serf the website I get a server error... after a reload I get every thing back to normal". I think that he gets 500 error. how can I log it? I want to know when and where it happens. any ideas?
500 errors are logged in your web server's error log, for Apache that is usually error.log. You should be able to find all errors there, including the requesting IP and the exact message.
If you don't have access to the error logs, if you have Apache, you can try this in a .htaccess file:
ErrorDocument 500 /my_error_handler.php
my_error_handler.php would then send out an E-Mail to you or something. This won't give you the exact error message, though.
According to the comments, this is not the case on Apache, but is the case on IIS. If you think the error is related to your PHP code then it's possible this is what's causing the status 500 error.
There are several ini directives you can set to deal with server errors. I recommend having error logging switched on. See the following site for each ini directive:
http://www.addedbytes.com/drafts/php-ini-guide/php-ini-guide-error-handling-and-logging/
Add/Change/Uncomment the ones you want in your php.ini file.
With logging switched on, the following php code generates the following error string in the error log file:
<?php this_is_undefined(); ?>
error log -
[05-Jan-2010 12:44:29] PHP Fatal error: Call to undefined function this_is_undefined() in D:\websites\leaguers.co.uk\test.php on line 1

Categories