ELIMINATING ERROR MESSAGES WHEN RECORD NUMBER IS NOT PASSED IN A DETAIL PAGE URL (BOTS) - Dec 25th, 2022


If you're using detail pages that pass a record number at the end of their URLs, bots can cause your Developer log to
fill up with hundreds of useless errors in a very short period.

Thanks to Jenna Cooke from Interactive Tools suggested the following solution.
She said: Try putting the following near the top of the page, after your getRecords call:

<?php if (!$your_sectionRecord) { dieWith404("Record not found!"); } // show error message if no record found ?>


Jenna's suggestion was very helpful, and solved the error log issue, but shows a blank white page with the words "Record
not found!".

Since there's a slim possibility that a live visitor is receiving the message and not a bot, I used a variation on the
theme that that redirects the visitor to a custom 404 page instead if a record is not found, using the following code in
the same location: (You'll have to create your own appropriate page for this purpose)

<?php if (!$your_sectionRecord) { header('Location: http://your_site.com/your_new_page.php'); die;} // show error page
if no record found ?>


Just remember that since you're setting an HTTP-header : you must not have sent any kind of output before (not even a
blank space at the end of an included file) or you'll throw a "Warning: Cannot modify header information - headers
already sent" error. Test your page after the modification to make sure that it works as planned, and proceed
accordingly.

The rub is that those blank spaces may not show up in your particular code editor.

When I encounter pages that throw a 'header' error, I find it easier to find a similar detail page and copy those load
viewer library and get records calls to the top of the faulty page. That usually solves the problem.



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service