Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Issue with form processing

I have a basic form on this website which sends user data to an email address. It is based on the form from - Building a simple PHP application - .

The form works completely fine, sending two emails, an automated email to the user who submitted it and an email address to the administrator (me). All validation checks are in place.

The error started occuring when I decided to tidy up the code and proceeded to copy the bot_validation code into an include file, and include it into my code. This is the validation code i'm trying to include:

                // Run a check for FORM HEADER INJECTOR bots.
                foreach($_POST as $value) {
                        // If malicious inputs are detected, exit code.

                        // Checks if value is array first to run validation on its elements.
                        if (gettype($value) == "array") {
                                // Checks if there are elements in the array
                                if(count($value) > 0) {
                                        foreach($value as $element) {
                                                if (stripos($element, 'Content-Type:') !== FALSE) {
                                                        echo "Invalid submission";
                                                        exit();
                                                }
                                        }
                                }
                        }
                        // If value is not an array, use the check below
                        elseif (stripos($value, 'Content-Type:') !== FALSE ) {
                                echo "Invalid submission";
                                exit();
                        }
                }

When this code is not included and instead present within the same file, everything works fine. Validation is good, email sending is good.

When this code is included however, once all validation is passed and the email is meant to be sent, the page just blanks after clicking "submit" on the form. The URL is still register.php, not register.php?display=thanks therefore I understand some procedure went wrong before sending the email, but how can that be related to the code above?

Hi Joey,

Can you post the page that this code was in which shows where you're including it?

Do you have your include file contained in <?php ?> tags? In the example above there aren't any.