Fropper.com - no one's a stranger
Already a member? Login here  | Tour | Help  
in




Posted on: Nov 07, '08


 PHP5 Filter Functions


PHP filters are used to validate and filter data coming from insecure sources.
e.g. User Inputs...

PHP filter_input() Function

With filter_input() function we can filter out the data from following sources.

1. INPUT_GET
2. INPUT_POST
3. INPUT_COOKIE
4. INPUT_ENV
5. INPUT_SERVER
6. INPUT_SESSION (Not yet implemented)
7. INPUT_REQUEST (Not yet implemented)

this function returns the filtered variable data on success and returns FALSE on the  failure or of filter action.

Syntax
filter_input(input_type, variable, filter, options)

input_type =  Above List of sources. e.g . INPUT_GET , INPUT_POST.
variable     =  Variable to be validated.
filter           =  Specifies the ID of the filter to use. Default is FILTER_SANITIZE_STRING.

Here is the list of php filters.
ID Name                                            Description
FILTER_CALLBACK------------------Call a user-defined function to filter data
FILTER_SANITIZE_STRING-------Strip tags, optionally strip or encode special characters
FILTER_SANITIZE_STRIPPED--- Alias of "string" filter
FILTER_SANITIZE_ENCODED--- URL-encode string, optionally strip or encode special
                                                            characters
FILTER_SANITIZE_SPECIAL_CHARS
                                                            HTML-escape '"<>& and characters with ASCII value less than
                                                            32
FILTER_SANITIZE_EMAIL----------Remove all characters, except letters, digits and               
                                                            !#$%&'*+-/=?^_`{|}~@.[]
FILTER_SANITIZE_URL------------Remove all characters, except letters, digits and $-_.+!*'(),
                                                            {}|\\^~[]`<>#%";/?:@&=
FILTER_SANITIZE_NUMBER_INT----Remove all characters, except digits and +-
FILTER_SANITIZE_NUMBER_FLOAT----Remove all characters, except digits, +- and optionally
                                                            .,eE
FILTER_SANITIZE_MAGIC_QUOTES----- Apply addslashes()
FILTER_UNSAFE_RAW----------------------- Do nothing, optionally strip or encode special
-------------------------------------------------------- characters
FILTER_VALIDATE_INT----------------------- Validate value as integer, optionally from the specified
-------------------------------------------------------- range
FILTER_VALIDATE_BOOLEAN-------------- Return TRUE for "1", "true", "on" and "yes", FALSE for
-------------------------------------------------------- "0", "false", "off", "no", and "", NULL otherwise
FILTER_VALIDATE_FLOAT------------------- Validate value as float
FILTER_VALIDATE_REGEXP---------------- Validate value against regexp, a Perl-compatible
------------------------------------------------------- regular expression
FILTER_VALIDATE_URL--------------------- Validate value as URL, optionally with required
------------------------------------------------------  components
FILTER_VALIDATE_EMAIL------------------  Validate value as e-mail
FILTER_VALIDATE_IP------------------------ Validate value as IP address, optionally only IPv4 or
------------------------------------------------------ IPv6 or not from private or reserved ranges


 



Tags: php, php filters




Comments  [ 1 Comments ] [ Post your comment | Subscribe (?) ]


Send MessageOfflineScrap

Prasad9686 said:
informative post .. keep it up...

December 03, '08

Want to comment on this post?

Register now, its FREE, and share your views.
Already a member? Login now.