木子炜培先生

⑴2017底=>(年薪15万)=>31岁 ⑵2018=》(生产生活用品)并且年薪20万=>32岁 ⑶2019=>年薪30万=>把小作坊升级为工厂=>33岁 ⑷2020=>再开一个食品工厂

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1

namespace common\components;
 
use Yii;
use yii\base\Component;
 
class ReadHttpHeader extends Component {
 
    public  function RealIP()
    {
        $ip = false;
 
        $seq = array('HTTP_CLIENT_IP',
                  'HTTP_X_FORWARDED_FOR'
                  , 'HTTP_X_FORWARDED'
                  , 'HTTP_X_CLUSTER_CLIENT_IP'
                  , 'HTTP_FORWARDED_FOR'
                  , 'HTTP_FORWARDED'
                  , 'REMOTE_ADDR');
 
        foreach ($seq as $key) {
            if (array_key_exists($key, $_SERVER) === true) {
                foreach (explode(',', $_SERVER[$key]) as $ip) {
                    if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
                        return $ip;
                    }
                }
            }
        }
    }
 
}

2在common/config/main-local.php

  //  新添加的
        'ReadHttpHeader' => [
            'class' => 'common\components\ReadHttpHeader'
        ],

3调用自定义组件backend\controllers\SiteController.php

public function actionIndex()
    {
         //自定义组件
        echo Yii::$app->ReadHttpHeader->RealIP();
        
        return $this->render('index');
    }

 

posted on 2017-02-04 00:37  木子炜培先生  阅读(268)  评论(0编辑  收藏  举报