Error Log showing error when frontend displays 404 not found.

8 posts by 4 authors in: Forums > CMS Builder
Last Post: June 10, 2015   (RSS)

By andybarn - May 9, 2015

Hi

I have a listings Real Estate site using CMSB.

If a user enters a link such as http://www.comparedirect.eu/property/listingDetail.php?19435 they get the listing detail page up - good

However if they key in an invalid URL such as http://www.comparedirect.eu/property/listingDetail.php?194355 they get the 404 page not found which is correct - good

However I notice this produces an error in the CMS Admin error log - the error says:-

E_WARNING: Invalid argument supplied for foreach()
/home/comparedirect/public_html/property/listingDetail.php (line 163)
http://www.comparedirect.eu/property/listingDetail.php?194355

Should this happen? How can I prevent this showing up in the error log as it is a 404 page not found.

Kind regards

Andy

By gregThomas - May 11, 2015

Hi Andy,

Would it be possible to post the code for listingDetail.php page? Then I can take a look into what might be causing the issue. 

You can e-mail me the code via support@interactivetools.com if you'd prefer.

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By In-House-Logic - May 14, 2015 - edited: May 14, 2015

I can verify this behaviour on one of our new sites also. Pages which fail to find a record in the initial query are redirected to a 404 page. Error logs still fire off though so I'm getting several each day from site sniffers.

Came on today to try to find some info about this. :)  Was going to ask if it was possible to get the error log to record the referring URL string as well as the page failure. I am thinking that users are arriving from mal-formed links on other pages but I have no way of knowing what page was sending them to the one throwing the error. I think this would still be useful and I'd love to know how to add this if possible.

Discovered that the error log in CMSB itself does capture the whole server request array. Found what I needed there.

J.

By Damon - May 14, 2015

Hi Andy,

Thanks for sending in the template.

To prevent the errors from appearring in the Error Log when records are not found, change this code:

if (!$listingsRecord) { header('Location: http://www.comparedirect.eu/404-compare-direct.php'); } // redirect to 404 page

to this code:

if (!@$listingsRecord) { header('Location: http://www.comparedirect.eu/404-compare-direct.php'); die; } // redirect to 404 page

I added the @ to the array (that doesn't exist) to suppress that error and the die statement after the redirect so no more code will be run (which generated an error).

Try this out and let me know if you have any questions.

Thanks!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Thanks Damon. Will also give this tweak a try.

Jayme

By andybarn - May 15, 2015

Thanks Damon

I put the code in and tested with an invalid URL and the 404 page came up AND there was no error in the error log file in Admin.

All good - thanks for your excellent support!

Kind regards

Andy

By In-House-Logic - June 10, 2015 - edited: June 10, 2015

Can also confirm that this solves the issue.

It seems like it helps to know what you're doing.

Thanks Damon!