Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 严格标准:在中不应静态调用非静态方法CountryDetector::countryMatches()_Php - Fatal编程技术网

Php 严格标准:在中不应静态调用非静态方法CountryDetector::countryMatches()

Php 严格标准:在中不应静态调用非静态方法CountryDetector::countryMatches(),php,Php,我试图限制一些国家,它的重定向到受限制的国家用户完美。但是,如果用户不是来自限制国家,则我的网站正在加载,但以下错误消息显示在网站顶部 严格标准:不应在第61行的C:\wamp\www\final\country\CountryDetector.class.php中静态调用非静态方法CountryDetector::countryMatches() 我在index.php文件上调用该类,如下所示: <?php include('/country/CountryDetector.cl

我试图限制一些国家,它的重定向到受限制的国家用户完美。但是,如果用户不是来自限制国家,则我的网站正在加载,但以下错误消息显示在网站顶部

严格标准:不应在第61行的C:\wamp\www\final\country\CountryDetector.class.php中静态调用非静态方法CountryDetector::countryMatches()

我在index.php文件上调用该类,如下所示:

<?php
    include('/country/CountryDetector.class.php');
    CountryDetector::redirect("DE", "http://google.com");
?>

我使用的类库是:

<?php


    include("CountryDetector.interface.php");

    /**
     * Class that lookup's for a country code then it redirects (include files, or callbacks) the user to desired content you want.
     * The function of this class is like Google that redirects users from countries that support google 
     * e.g. in UK when you enter google.com you will be redirected to google.co.uk and this is excatly 
     * what you can do with CountryDetector
     *
     * This class is builded in static context for purpose of best usage


    class CountryDetector implements CountryDetectorInterface
    {
        private static $current_country;

        private static $include_done;


        /** Defined Countries */
        private static $BALKANS = array("AL", "BA","HR", "RS", "ME", "BG", "MK", "GR");

        private static $EUROPE = array("AL", "AD", "AM", "AT", "AZ", "BY", "BE", "BA", "BG", "HR", "CY", "CZ", "CS", "DK", "EE", "FI", "FR", "FX", "GE", "DE", "GR", "HU", "IS", "IE", "IT", "KZ", "LV", "LI", "LT", "LU", "MK", "MT", "MD", "MC", "ME", "NL", "NO", "PL", "PT", "RO", "RU", "SM", "RS", "SI", "ES", "SE", "CH", "TR", "UA", "UK", "VA");

        private static $MIDDLEEAST = array("TR", "BH", "KW", "OM", "QA", "SA", "AE", "YE", "PS", "IQ", "IL. JO", "LB", "SY", "IR", "CY", "EG");

        private static $ASIA = array("AF", "AM", "AZ", "BH", "BD", "BT", "IO", "DN", "KH", "CN", "CX", "CC", "GE", "HK", "IN", "ID", "IR", "IQ", "IL", "JP", "JO", "KZ", "KP", "KR", "KW", "KG", "LA", "LB", "MO", "MY", "MV", "MN", "NP", "OM", "PK", "PS", "PH", "QA", "RU", "SA", "SG", "LK", "SY", "TW", "TJ", "TH", "TP", "AE", "UZ", "VN", "YE");

        private static $AMERICA = array("US", "BZ", "CR", "SV", "GT", "HN", "NI", "PA", "MX", "HT", "CU", "AR", "BO", "BR", "CL", "CO", "EC", "FK", "GF", "GY", "PY", "PE", "SR", "UY", "VE");

        private static $NORTHAMERICA = array("US");

        private static $SOUTHAMERICA = array("AR", "BO", "BR", "CL", "CO", "EC", "FK", "GF", "GY", "PY", "PE", "SR", "UY", "VE");

        private static $CENTRALAMERICA = array("BZ", "CR", "SV", "GT", "HN", "NI", "PA", "MX", "HT", "CU");

        private static $CARIBBEAN = array("AI", "AG", "AW", "BS", "BB", "VG", "KY", "CU", "DM", "DO", "GD", "GP", "HT", "JM", "MQ", "MS", "AN", "PR", "KN", "LC", "VC", "TT", "TC", "VI");


        /**
         * Redirect to URL based on country code
         *
         * @param $country - Country that want to apply this rule
         * @param $url - If country matches then will be redirected to this url
         *
         * @return void
         */

        public static function redirect($country, $url, $except = null)
        {
            self::_lookup();

            $matches = self::countryMatches($country, $except);

            if( $matches )
            {
                if( !@header("Location: $url") )
                {
                    print('<script type="text/javascript"> window.location = "'.$url.'"; </script>');
                }               
            }
        }


        /**
         * Use reserved word `include` to require a file based on country code
         *
         * @param $country - Country that want to apply this rule
         * @param $include_path - If country matches then will be included the selected file
         *
         * @return void
         */

        public static function includeFile($country, $include_path, $except = null)
        {
            self::_lookup();

            $matches = self::countryMatches($country, $except);

            if( $matches )
            {
                include($include_path);
            }
        }


        /**
         * Include Once - It will include just one time file
         *
         * @param $country - Country that want to apply this rule
         * @param $include_path - If country matches then will be included the selected file
         *
         * @return void
         */

        public static function includeFileOnce($country, $include_path, $except = null)
        {
            if( !self::$include_done )
            {
                self::_lookup();

                $matches = self::countryMatches($country, $except);

                if( $matches )
                {
                    include($include_path);
                    self::$include_done = true;
                }
            }
        }


        /**
         * Call's specified function based on country code
         *
         * @param $country - Country that want to apply this rule
         * @param $callback_func - If country matches then the function named $callback_func() will be called (with no parameters)
         *
         * @return void
         */

        public static function callback($country, $callback_func, $except = null)
        {
            self::_lookup();

            $matches = self::countryMatches($country, $except);

            if( $matches )
            {
                call_user_func($callback_func);
            }
        }


        /**
         * Lookup's for a country (based on IP)
         *
         * @return void
         */

        private static function _lookup()
        {
            if( !self::$current_country )
            {
                $remote_addr = $_SERVER['REMOTE_ADDR'];
                $api_url = str_replace("#REMOTE_ADDR#", $remote_addr, self::IP_API_URL);

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $api_url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $country_code = curl_exec($ch);
                curl_close($ch);

                self::$current_country = strtoupper($country_code);             
            }
        }


        /**
         * Check if country matches with the country parameter
         *
         * @return boolean - true if it matches, false if not
         */

        private function countryMatches($country, $except)
        {
            $cs = $country;

            if( ! is_array($country) )
            {
                switch( strtoupper($country) )
                {
                    case "AMERICA":
                        $country = self::$AMERICA;
                        break;

                    case "ASIA":
                        $country = self::$ASIA;
                        break;

                    case "BALKANS":
                    case "BALKAN":
                        $country = self::$BALKANS;
                        break;

                    case "CARIBBEAN":
                        $country = self::$CARIBBEAN;
                        break;

                    case "CENTRALAMERICA":
                        $country = self::$CENTRALAMERICA;
                        break;

                    case "EUROPE":
                        $country = self::$EUROPE;
                        break;

                    case "MIDDLEEAST":
                    case "MIDDLE EAST":
                        $country = self::$MIDDLEEAST;
                        break;

                    case "NORTHAMERICA":
                    case "UNITED STATES":
                        $country = self::$NORTHAMERICA;
                        break;

                    case "SOUTHAMERICA":
                    case "LATIN AMERICA":
                        $country = self::$SOUTHAMERICA;
                        break;

                    default:
                        $country = array($country);
                }
            }

            if( is_array($except) )
            {
                foreach($except as $except_country)
                {
                    if( $except_country == self::$current_country )
                        return false;
                }
            }

            if( $cs == "*" || strtoupper($cs) == "INTERNATIONAL" )
                return true;

            if( in_array(self::$current_country, $country) && !in_array($except, $country) )
            {
                return true;
            }

            return false;
        }


        /* v1.1 */

        // Get Country Code of current country
        public static function getCountryCode()
        {
            if( ! self::$current_country)
            {
                self::_lookup();
            }

            return self::$current_country;
        }

        public static function is($country_code)
        {
            if( ! self::$current_country)
            {
                self::_lookup();
            }

            $cc = strtolower(self::$current_country);
            $country_code = strtolower($country_code);

            return $cc == $country_code;
        }
    }   
?>

您的方法是countyMatches不是静态声明的,只是
私有静态函数countryMatches($country,$except)

那么我可以如何解决这个问题?我对此不太了解,只需将此“私有函数countryMatches($country,$Exception)”更改为此“私有静态函数countryMatches($country,$Exception)”就可以了