Search code examples
phpfilter-var

PHP FILTER_VALIDATE_EMAIL return different values on different machines


I tested form validators for email field and inputted long email:

 $email = 'dfgjfdjglkdfjglkjdfgldfjglkdfjgkldfjlkgjdlkfjglkdfjkgdklfjgldkfjgldlfjgkldfjglkdfjglkdfklgjlkdfjkgkdfjlkgfjldkgkldjfgkljdfkgjlkdfgljdlf@mail.com';

On the local machine function filter_var return string with email:

 $email = 'dfgjfdjglkdfjglkjdfgldfjglkdfjgkldfjlkgjdlkfjglkdfjkgdklfjgldkfjgldlfjgkldfjglkdfjglkdfklgjlkdfjkgkdfjlkgfjldkgkldjfgkljdfkgjlkdfgljdlf@mail.com';

 die(var_dump(filter_var($email, FILTER_VALIDATE_EMAIL)));

But on the remote server this code returns FALSE.

PHP version on local machine - 5.3.2-1ubuntu4.22

On the remote machine - 5.3.28

Has filter_var function been changed between this version of PHP? Why I receive different values with the same code?


Solution

  • FILTER_VALIDATE_EMAIL has been updated a couple of times since 5.3.2 (you really should update your version BTW). The most notable update was this bug-fix causing a seg-fault when the input/address-to-validate was too long.
    Along side this fix (which is logged twice), Rasmus Lerdof on FILTER_VALIDATE_EMAIL returning false positives. Though, AFAIKT, this is not likely to be the cause of your woes.
    A couple of other changes include bugs involving special chars like ?, >1 and =.
    Anyway, to see all the changes since PHP5.3.2, just check the changelog on their website...

    Again: update your local version, it's getting rather dated. Given that you're running ubuntu:

    $ sudo apt-get install php5-dev
    //optionally
    $ sudo apt-get install php5-dev --install-suggests
    

    If you're running mint:

    $ sudo apt-get install php5-dev --install-recommends --install suggests
    

    on both distro's, preferably run sudo apt-get update first, of course...