Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

php - How consistent is FILTER_VALIDATE_EMAIL?

Sample valid e-mail address:

"this is a valid address"@example.com

PHP code:

<?php
header('Content-Type: text/plain');

$email = '"this is a valid address"@example.com';
$checked = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($email, $checked);

Output on one server: (PHP Version 5.2.6):

string(37) ""this is a valid address"@example.com"
string(37) ""this is a valid address"@example.com"

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 1.52.2.42 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

Output on another server (PHP Version 5.3.3):

string(37) ""this is a valid address"@example.com"
bool(false)

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 298196 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

I cannot see anything in the documentation to suggest that this has changed, so perhaps it's some other configuration setting.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As you can see on http://3v4l.org/vKONS the usage of the filter FILTER_VALIDATE_EMAIL it is not consistent!

http://3v4l.org/vKONS outputs for PHP 5.2.0, 5.2.14 - 5.2.17, 5.3.3 - 5.3.18, 5.4.0 - 5.4.8

string(37) ""this is a valid address"@example.com" 
bool(false)

and for 5.2.1 - 5.2.13, 5.3.0 - 5.3.2

string(37) ""this is a valid address"@example.com" 
string(37) ""this is a valid address"@example.com"

It is remarkable that it worked for 5.2.0 but not 5.2.1-5.2.13 and then again for 5.2.14!!!

Btw 3v4l.org is a great resource to check such behavior changes across all available PHP versions.

There are several bugs open including the term FILTER_VALIDATE_EMAIL, but none seems to match your kind of error. You might add it to the PHP bugtracker...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...