Example of CompeteAPI usage for php website access statistics

Source: Internet
Author: User
Tags php website
This article mainly introduces the usage of CompeteAPI in the php website access statistics class. The example analyzes php's skills in using curl to obtain Compete website information, which has some reference value, for more information about how to use the Compete API in php to obtain website access statistics, see the following example. Share it with you for your reference. The details are as follows:

Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.

 This example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:

Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.

___FCKpd___0

I hope this article will help you with php programming.

UrlKeys = array (': domain', ': metric', ': key'); private

This example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:

Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.

___FCKpd___0

I hope this article will help you with php programming.

ApiKey;/*** For url cleaning. */private

This example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:

Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.

___FCKpd___0

I hope this article will help you with php programming.

ToSearch = array ('http: // ', 'www.'); private

This example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:

Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.

___FCKpd___0

I hope this article will help you with php programming.

ToReplace = array ('','');/*** List of available metrics. */private

This example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:

Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.

___FCKpd___0

I hope this article will help you with php programming.

AvailableMetrics = array (// Description Auth type 'uv', // Unique Visitors Basic 'vis ', // Visits Basic 'rank', // rank Basic 'pv ', // Page Views All-Access 'avstay', // Average Stay All-Access 'vps', // Visits/Person All-Access 'vppu ', // Pages/Visit All-Access 'Att ', // Attention All-Access 'reachd', // Daily Reach All-Access 'attd ', // Daily Attention All-Access 'Gen', // Gender All-Access 'age', // age All-Access 'INC', // Income All-Access ); /*** List of available methods for _ call () implementation. */private

This example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:

Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.

___FCKpd___0

I hope this article will help you with php programming.

Metrics = array ('uniquevisitors '=> 'u', 'visits' => 'vis ', 'rank' => 'rank ', 'pageview' => 'PV ', 'averagestay' => 'avstay', 'visitsperson '=> 'vps', 'pagesvisit' => 'vppu', 'attention' => 'Att ', 'dailyad' => 'reachd', 'dailyattention '=> 'attd', 'gender' => 'Gen', 'age' => 'age ', 'Welcome '=> 'INC');/*** Create access to Compete API. * @ param string $ apiKey user's api key. */public functi On _ 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 );}}

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.