Php

thinkphp5in_array関数で大文字と小文字を区別しない実装



Thinkphp5 In_array Function Case Insensitive Implementation



たとえば、訪問するリンクは次のとおりです。 http:// www .Domain name.com/mobile.php/User/getCode.html
ユーザーコントローラーのgetCodeメソッドにアクセスします

$request = thinkRequest::instance() $action = $request->action()//The method obtained here is lowercase (getcode) //Do not need to log in $no_login_action = array('login','do_login','logout','register','getCode','jsonRegionC','jsonRegionD') //Not logged in processing $this->user_id = session::get('user_id') ? session::get('user_id') : '' if(empty($this->user_id)){ if(!in_array(strtolower($action),array_map('strtolower',$no_login_action))){ header('Location:'.url('User/login'))exit } }

大文字と小文字を区別しない実装コードは次のとおりであり、メソッドと渡されたものは小文字に変換されます。



in_array(strtolower($action),array_map('strtolower',$no_login_action)