filter_var in php 5.3.8

后端 未结 4 1453
误落风尘
误落风尘 2021-01-20 01:51

I am developing a user registration form and want to validate a user\'s email address. However,all the php docs I have read suggest the use of filter_var. My script validate

相关标签:
4条回答
  • 2021-01-20 02:32

    In your case you shouldn't use filter_var, but filter_input. This is all the code you would need:

    if ($email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) {
        // email was submitted and is a valid email
    }
    

    This bug might be related to your problem though.

    0 讨论(0)
  • 2021-01-20 02:42
      if(isset($_POST['email'])== true && empty($_POST['email'])false)
                               ^^^^^^^--redundant               ^^^^^---typo?
    
    0 讨论(0)
  • 2021-01-20 02:46
    $email = isset($_POST['email']) ? $_POST['email'] : "";
    echo(filter_var($email,FILTER_VALIDATE_EMAIL) ? "valid email" : "invalid email");
    
    0 讨论(0)
  • 2021-01-20 02:49
    if(isset($_POST['email'])== true && empty($_POST['email'])false)
    

    this should be

    if(isset($_POST['email']) && !empty($_POST['email']) )
    

    or as @jack you can use just

    if (!empty($_POST['email']))
    

    the empty() does implicit isset()

    0 讨论(0)
提交回复
热议问题