PHP Filtering

Discussion in 'PHP' started by Dehisce, Nov 1, 2009.

  1. #1
    Whats the best method to filter posted forms nowadays? I have only used strip in the passed by I suspect its changed alot now?

    I want to filter a username and other like fields.

    Thanks
     
    Dehisce, Nov 1, 2009 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  3. Dehisce

    Dehisce Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    function stripvar($string)
    {
     return preg_replace('/[^a-zA-Z0-9\s]/', '', $string);
    }
    Code (markup):
    How do I edit this to allow these....
     @ . ? = / 
    Code (markup):
     
    Last edited: Nov 1, 2009
    Dehisce, Nov 1, 2009 IP
  4. tonythetiger

    tonythetiger Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I agree with nico_swd, dont't use regular expressions to do your filtering, as of php 5.2 there is built in filtering that you can allow certain characters and such. This is industry standard now and the day of regular expressions to filter, urls, get, post, etc.. data is long gone and not recommended, unless you have a very special circumstance.
     
    tonythetiger, Nov 1, 2009 IP
  5. Dehisce

    Dehisce Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't understand the filters. Are these for just checking variables or actually filtering them?
     
    Dehisce, Nov 2, 2009 IP
  6. Dehisce

    Dehisce Peon

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Have I understood this right...

    function sanemail ($string) {
    $string = filter_var($string, FILTER_SANITIZE_EMAIL);
    return $string;
    }

    $email = "Jo^&*hn@()smi%£$th.c££om";
    echo sanemail($email);

    Would this return "John@smith.com" ?
     
    Dehisce, Nov 2, 2009 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Both.

    There are validation and sanitation filters.

    Trying it usually results in faster responses. ;)
     
    nico_swd, Nov 3, 2009 IP