codeigniter idn_to_ascii():INTL_IDNA_VARIANT_2003已过时

u91tlkcl  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(108)

I am using codeigniter framework for my site, but in form_validation I am getting error I followed this link in stackoverflow but it didn't work for me followed link: idn_to_ascii() in 5.2.17
Issue:

code in codeigniter libraries/form_validation.php:

public function valid_email($str)
    {
        if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
        {
            $domain = defined('INTL_IDNA_VARIANT_UTS46')
                ? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46)
                : idn_to_ascii($matches[2]);

            if ($domain !== FALSE)
            {
                $str = $matches[1].'@'.$domain;
            }
        }

        return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
    }
ygya80vv

ygya80vv1#

理想的解决方案是upgrade ICU to its latest version
由于这在我的共享服务器上是不可能的,因此我解决了该问题,扩展了CI电子邮件库:

  • 否决了valid_email()函数,该函数使用INTL_IDNA_VARIANT_UTS46,不幸的是,我的服务器上没有安装该函数。
  • PhP 7.2支持该版本,因此如果您安装了INTL_IDNA_VARIANT_2003,则会收到上面的已弃用错误消息。
  • 解决方案:你需要从2.0版本的电子邮件库返回valid_email()函数:
class MY_Email extends CI_Email {

  public function valid_email($address)
  {
     return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE;
  }

}

将此扩展类作为MY_email. php保存在您的application/libraries文件夹中。关于扩展原生库,前缀MY_是可配置的。

相关问题