Jump to content

4 Questions About PHP Filter


Renegade605
 Share

Recommended Posts

Page at http://www.theunitedfrontclan.com/recruitment.phpFirst Question: I have a form, which submits data to itself. At the start of the code it checks to see if it has input, if it doesn't it ouputs a form to the page. If it does, it's supposed to run the data through a filter. Unfortunatly, instead of doing that, it comes up with an error; Call to undefined function: filter_input_array(). Last I checked that was a function, and it's in the PHP tutorial here. So what gives?Second Question: With strings, the only filter I can find to run them through is FILTER_SANITIZE_STRING, but I don't want the filter to just take something out. Instead, how can I have the filter check for invalid characters, and simply report when they are present?Third Question: If I use the filter_input_array() function, does that also return errors when there is no data present? If not, how do I check that all fields have been filled?Last Question: If input for specific fields ('time' and 'skill' in this case) are from drop-down selection boxes. Should I still use a filter on them?

Link to comment
Share on other sites

1. The filter_input_array function requires PHP 5 >= 5.2.0. Check your installed version.2. If you want to detect if characters are present in a string, use the strpos function. If you want to detect if more then one character is in a string, the easiest way is to probably use str_replace to replace all of the characters you want to detect, and then compare the replaced string with the original. If they are different then one or more of the characters were found.3. From the documentation:

An array value will be FALSE if the filter fails, or NULL if the variable is not set. Or if the flag FILTER_NULL_ON_FAILURE is used, it returns FALSE if the variable is not set and NULL if the filter fails.
That doesn't detect if a variable was set but had nothing in it. In that case you will want to check yourself.4. You should always filter anything that comes from $_GET, $_POST, or $_COOKIE.Check the documentation for more information:http://www.php.net/manual/en/function.filter-input-array.php
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...