您好,欢迎访问一九零五行业门户网

php获得网站访问统计信息类Compete API用法实例,访问统计compete_PHP教程

php获得网站访问统计信息类compete api用法实例,访问统计compete本文实例讲述了php获得网站访问统计信息类compete api用法。分享给大家供大家参考。具体如下:
这里使用php获得网站访问统计信息类compete api,compete是一个专门用来统计网站信息的网站
'uv', 'visits' => 'vis', 'rank' => 'rank', 'pageviews' => 'pv', 'averagestay' => 'avgstay', 'visitsperson' => 'vpp', 'pagesvisit' => 'ppv', 'attention' => 'att', 'dailyreach' => 'reachd', 'dailyattention' => 'attd', 'gender' => 'gen', 'age' => 'age', 'income' => 'inc' ); /** * create access to compete api. * @param string $apikey user's api key. */ public function __construct($apikey) { $this->_apikey = $apikey; } /** * implement specific methods. */ public function __call($name, $args) { if (array_key_exists($name, $this->_metrics) && isset($args[0])) return $this->get($args[0], $this->_metrics[$name]); throw new competeexception($name . ' method does not exist.'); } /** * get data from compete. * @param string $site some domain. * @param string $metric metric to get. * @return stdclass compete data. * @throws competeexception */ public function get($site, $metric) { if (!in_array($metric, $this->_availablemetrics)) throw new competeexception($metric . ' - wrong metric.'); $values = array( $this->_prepareurl($site), $metric, $this->_apikey ); // prepare call url $url = str_replace($this->_urlkeys, $values, self::api_base_url); // retrieve data using http get method. $data = json_decode($this->_get($url)); // because of unsuccessful responses contain status_message. if (!isset($data->status_message)) return $data; throw new competeexception('status: ' . $data->status . '. ' .$data->status_message); } /** * cut unnecessary parts of url. * @param string $url some url. * @return string trimmed url. */ private function _prepareurl($url) { return str_replace($this->_tosearch, $this->_toreplace, $url); } /** * execute http get method. * @param string $url request url. * @return string response. */ private function _get($url) { $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_useragent, self::user_agent); curl_setopt($ch, curlopt_returntransfer, true); return curl_exec($ch); }}
希望本文所述对大家的php程序设计有所帮助。
http://www.bkjia.com/phpjc/978380.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/978380.htmltecharticlephp获得网站访问统计信息类compete api用法实例,访问统计compete 本文实例讲述了php获得网站访问统计信息类compete api用法。分享给大家供大家...
其它类似信息

推荐信息