New Discussion using PHP to record

Source: Internet
Author: User

If you use a good record analyzer, such as Analog or something similar, it is not too difficult to figure out where your website is clicked and which web pages have been browsed.

However, if you want to stop a running report, you must use a different route.

About six months ago, I was introducing Apache records to an SQL database and then made a special query on him.

Unfortunately, I have to manually capture these records one by one, reverse them a little, and then output them. I want something better-something that can be updated continuously, information that can be browsed, statistical tables of browsers and platforms, and trends over time.

The solution version of this article can be used for years. I raised his importance when we established SourceForge through the SourceForge system, all records and tracks through this SourceForge.net website pipeline, include the web page viewer on the website and each web page viewer on the 1200 project.

Basically, each record operation I want to perform is to add a column to the data table of a database (in this example, it is a Web browser, however, you can record the number of page views added to the banners on other websites .. and so on)

This is the data table structure I am using on SourceForge:

Create table activity_log (
Day integer DEFAULT 0 not null,
Hour integer DEFAULT 0 not null,
Group_id integer DEFAULT 0 not null,
Browser varchar (8) default other not null,
Ver float (10) DEFAULT 0.00 not null,
Platform varchar (8) default other not null,
Time integer DEFAULT 0 not null,
Page text,
Type integer DEFAULT 0 NOT NULL


);

If you want to record multiple URLs, you can use the group_id column. you only need to assign a different group_id to each URL and pass it to the URL address (shown below ).

Type has never been used in these examples, but you can use it to track different types of behaviors, such as the number of ad clicks, the number of clicks from other websites, and so on.

One step that browser, ver, and platform can send to the website server from your browser is to transfer the data to the data table. it would be a perfect world if all the websites in the box via PHP are useful. unfortunately, I have a large number of servers distributed throughout the country, and I need to collect information on each web page of each server 24 hours a day.

So I have to use a 1x1 pixel GIF tip. I have a GIF on every server page and it looks like this:



There are four components in this graph

Remote web server
Web browser)
Central logging server
Central database server

Therefore, when a user visits the website and obtains a webpage for use, the browser requests a 1x1 GIF image to the server center. The server center records the information to make the production report easier.

Report Table

You only need to write some simple SQL statements to generate all the data.
You can also use the ShowResults () function to display data in Graphs (refer to prior article)

Now I can execute my statistical report at any time

Sample SQL to run reports
Page Views By Day

SELECT day, count (*)
FROM activity_log
WHERE type = 0 group by day

Page Views By Browser

SELECT browser, count (*)
FROM activity_log
WHERE type = 0 group by browser

Page Views By Browser Version

SELECT browser, ver, count (*)
FROM activity_log
WHERE type = 0 group by browser, ver

Page Views By Platform

SELECT platform, count (*)
FROM activity_log
WHERE type = 0 group by platform

Here. Zip contains browser detection and database entity action libraries.

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.