public function authenticate() { $record = User::model()->findByAttributes(array('username' => $this->username, 'is_active' => 1)); if (!$record) { $record = User::model()->findByAttributes(array('email' => $this->username, 'is_active' => 1)); } if ($record === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($record->password !== md5($this->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->_id = $record->id; $this->setState('userId', $record->id); $this->setState('username', $record->username); $this->setState('usertype', $record->user_type); $this->errorCode = self::ERROR_NONE; include_once Yii::app()->basePath . '/../ip2locationlite.class.php'; //Load the class $ipLite = new ip2location_lite(); $ipLite->setKey('6d81a70b31f21d507cdf42cc2d3d9f2f2592821074b0e5191012c1584a68c9cb'); //Get errors and locations $locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']); $errors = $ipLite->getError(); //Getting the result Yii::app()->session['latitude'] = $locations['latitude']; Yii::app()->session['longitude'] = $locations['longitude']; Yii::app()->session['isLoggedIn'] = true; } } return !$this->errorCode; }
<?php require_once "includes/functions.php"; require_once "includes/db_connection.php"; $ip = $_SERVER['REMOTE_ADDR']; $query_string = $_SERVER['QUERY_STRING']; $http_referer = $_SERVER['HTTP_REFERER']; $http_user_agent = $_SERVER['HTTP_USER_AGENT']; include 'includes/layouts/ip2locationlite.class.php'; //Load the class $ipLite = new ip2location_lite(); $ipLite->setKey('ADD_API_KEY_HERE'); //Get errors and locations $locations = $ipLite->getCity($ip); $errors = $ipLite->getError(); //Getting the result if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { if ($field == 'countryName') { $country = $val; } if ($field == 'cityName') { $city = $val; } } } if (is_bot()) { $isbot = 1; } else { $isbot = 0; }