Counter detailed design_PHP tutorial
Overview:
This design can design a counting analysis program based on this counter, which can analyze the number of page visits and IP visits, and form a report.
1. Database design
The database uses mysql
Related files: createDatabase.sql Create database
createTblCounter.sql Create counter table
Table name: tpCounter (table of pages counter)
field:
Name Type Meaning
id Int (10) auto_increment Serial number
pagename varchar(20) Page identification, the default is page file name
count Int(10) Count Value
Table name: tiCounter (table of ip counter)
Field:
Name Type Meaning
id Int(10) auto_increment Serial number
ip varchar(20) Ip identification
count Int(10) The number of times the IP has been visited
date datetime The most recent access time
pages text The page IDs that have been visited, separated by '|'
2. Detailed description:
1. You can count each page, or you can count the number of visits to each IP, the most recent visit time, and the pages visited each time. Two tables are needed;
2. Count the number of website visitors: Set one in tpCounter Site identification [it is recommended to use the pagename='0' flag];
3. Check the session every time you open the page. If the user's session does not exist, it means that you have just started to visit this website. Create a user at this time session, the website count increases by 1, and the visited page count increases by 1; [when opening or refreshing the page] If the user session already exists, the website count value does not increase, but the page count value increases by 1 every time it is refreshed;
4. When closing the page, check whether the number of pages the user has opened on this website is 0. If so, destroy the user's session, otherwise it will not be destroyed; [This function does not require writing a program, the server automatically executes it]
5. If the page is not identified in tpCounter during the visit, a record will be automatically inserted into the table;
6. Pages is a text type that records the time the viewer visited and the page visited, which contains a string in a format similar to this:
||2001-5-1 16:00:00|1|12|5||2001-8-3 10:12:5|4|9|
means that this ip is in 2001-5-1 Visited pages 1, 12, and 5 at 16:00:00, and visited pages 5, 4, and 9 at 2001-8-3 10:12:5 [the page number is obtained from the previous table];
7, Design the counting file (.php). Each page contains this file. This file contains the following functions:
1>session check,
2>connect to the database,
3>Count [parameters are Page name, IP, current time],
4> Read and write the database,
5> Disconnect from the database;
8. The visited pages are recorded in the following way:
User When opening a new page, if the user session does not exist, write the time and record the current page. If it exists, write the current page. Writing is done in an appended manner.
9. The website count is in this header file, and the page count is in the counted pages.
10. When each page includes this file, if you want to count the pages, you must use the variable $page_name before including it, and assign it to the name of the page. Page names cannot be repeated.
3. Interface description:
Related files: counter.php
1/Boolean check_session()
Function description: session check, return true if it exists; return true if it does not exist false, and create and register the Boolean variable existing
Entry parameters: None
Exit parameters: Boolean
2/site_count($content)
Function description: Website visit count
Entry parameters : Database connection
Exit parameters: Count value
3/page_count($connect,$page_name,$flag=true)
Function description: Count of web pages, return the number of page visits, integer, $ flag is a flag indicating whether to increase the count, the default is true
Entry parameters: $connect: database connection, $page_name: web page name
Exit parameters: number of page visits
4/show_site_count( int type)
Function description: Display count
Entry parameters: type==1 uses graphic counting
type==2 uses text counting
4. Process
0/check entry Permissions of the page
Since the header file needs to be compiled by reference, it must be checked whether it is passed by reference or browsed directly
1/Link to the database
2/Check the session, if it does not exist, create the session and count the website
3/Display count
4/Perform page count
5/Disconnect from the database [automatic implementation]
5. Usage
All functions are included in one In the header file, when using it, just include this header file.
6. Attached source program
/**counter.php v1.0
* by Amio 2001-5-1
* Description: counter file, can count the entire website,
* can count all pages, can count each ip
*/
/**Interface implementation function:
* 1>session check
* 2>Connect to database
* 3>Count
* 4>Read and write database
* 5>Table output of link part
*/
/**Usage:
* This file must be included in other php files.
* You need to configure the $inc variable before quoting.
* e.g.:
* * $ inc="inc";
* include("include.php");
*
* ?>
*/
?>
//session check, return Boolean
//true - this user session exists
//false - this user session does not exist
function check_session(){
$existing=true;
session_start();
if (!session_is_registered("existing")){
session_register("existing");
return false;
} else return true;
}
//Web page count, returns the number of page visits, integer
//$flag is a flag indicating whether to increase the count, default true
function page_count($connect ,$page_name,$flag=true){
$ip = getenv("REMOTE_ADDR");
$query=@mysql_query("select id,count from tpcounter where pagename='$page_name'",$connect ) or die("invalid page query!");
if (!(mysql_num_rows($query))){
mysql_query("insert into tpcounter (pagename,count) values('$page_name',1) ",$connect)or die("insert page failed");
$pidquery=@mysql_query("select id from tpcounter where pagename='$page_name'",$connect) or die ("select page id failed" );
$pidarray=mysql_fetch_array($pidquery);
$pid=$pidarray[id]; $array=mysql_fetch_array($query );
$num=$array[count]; $pid=$array[id]; if ($flag)
$num++; mysql_query("update tpcounter set count =$num where pagename='$page_name'",$connect)or die("update page failed");
$return_num=$num; from ticounter where ip='$ip'",$connect) or die ("invalid pages query!");
if (($flag)&&(mysql_num_rows($pquery))){
$parray= mysql_fetch_array($pquery);
$ps="$parray[pages]";
$pstr="$parray[pages]"."$pid"."|"; ticounter set pages='$pstr' where ip='$ip'",$connect)or die ("update ip failed");
}
return $return_num;
}
//ip count, returns the number of ip accesses, integer
//In addition to counting, it also has time update function
//$flag is a flag for whether to increase the count, the default is true
//Note: The call to ip_count must be before page_count!!!
function ip_count($connect){
$ip = getenv("REMOTE_ADDR");
$visit_time=date ("Y:m:d:H:i");
$visit_pages="||"."$visit_time"."|";
$ipquery=@mysql_query("select count,pages from ticounter where ip='$ip'",$connect) or die ("invalid ip query!");
if (!(mysql_num_rows($ipquery))){//New ip
$ pageStr="|"."$visit_pages"; mysql_query("insert into ticounter (ip,count,date,pages) values ('$ip',1,'$visit_time','$pageStr')", $connect)or die("insert ip failed");
return 1;
}else{ //Old ip
$parray=mysql_fetch_array($ipquery);
$ipnum=$ parray [count];
$pageStr="$parray[pages]"."$visit_pages";
$ipnum++;
mysql_query("update ticounter set count=$ipnum,date='$visit_time', pages='$pageStr' where ip='$ip'",$connect)or die("update ip failed");
return $ipnum; 🎜>//Site count, returns integer, number of website visits
function site_count($connect){
if (!check_session()){ //session does not exist
$ipnum=ip_count($connect );
$num=page_count($connect,"website",true); > }
return $num;
}
function displayCount($num){
$fileurl="countpng.php?count=".$num;
return $fileurl ;
}
//Display count value, type is the display type, length is the displayed length, default 6
//type=1 graphic form
//type=2 text Form (default)
function show_site_count($num,$length=6,$type=2){
$outStr=strval($num);
for ($i=strlen( $outStr)+1;$i<=$length;$i++){
:
echo " echo displayCount($outStr);
echo "">";
break;
case 2:
default:
echo "$outStr";
}
}
?>
if (!isset($inc))exit;
$connect=mysql_connect('localhost','root' ,'');//connect to server
mysql_select_db("damio",$connect); //select database ,database name is damio
$sitecount=site_count($connect);
if (isset($page_name))
page_count($connect,$page_name);
?>
http://www.bkjia.com/PHPjc/315284.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/315284.html
TechArticle
Overview: This design can design a counting analysis program based on this counter, which can calculate the number of page visits and IP visits Conduct analysis and form reports. 1. Database design Database acquisition...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The default map on the iPhone is Maps, Apple's proprietary geolocation provider. Although the map is getting better, it doesn't work well outside the United States. It has nothing to offer compared to Google Maps. In this article, we discuss the feasible steps to use Google Maps to become the default map on your iPhone. How to Make Google Maps the Default Map in iPhone Setting Google Maps as the default map app on your phone is easier than you think. Follow the steps below – Prerequisite steps – You must have Gmail installed on your phone. Step 1 – Open the AppStore. Step 2 – Search for “Gmail”. Step 3 – Click next to Gmail app

Is the clock app missing from your phone? The date and time will still appear on your iPhone's status bar. However, without the Clock app, you won’t be able to use world clock, stopwatch, alarm clock, and many other features. Therefore, fixing missing clock app should be at the top of your to-do list. These solutions can help you resolve this issue. Fix 1 – Place the Clock App If you mistakenly removed the Clock app from your home screen, you can put the Clock app back in its place. Step 1 – Unlock your iPhone and start swiping to the left until you reach the App Library page. Step 2 – Next, search for “clock” in the search box. Step 3 – When you see “Clock” below in the search results, press and hold it and

According to news on April 26, ZTE’s 5G portable Wi-Fi U50S is now officially on sale, starting at 899 yuan. In terms of appearance design, ZTE U50S Portable Wi-Fi is simple and stylish, easy to hold and pack. Its size is 159/73/18mm and is easy to carry, allowing you to enjoy 5G high-speed network anytime and anywhere, achieving an unimpeded mobile office and entertainment experience. ZTE 5G portable Wi-Fi U50S supports the advanced Wi-Fi 6 protocol with a peak rate of up to 1800Mbps. It relies on the Snapdragon X55 high-performance 5G platform to provide users with an extremely fast network experience. Not only does it support the 5G dual-mode SA+NSA network environment and Sub-6GHz frequency band, the measured network speed can even reach an astonishing 500Mbps, which is easily satisfactory.

Are you getting "Unable to allow access to camera and microphone" when trying to use the app? Typically, you grant camera and microphone permissions to specific people on a need-to-provide basis. However, if you deny permission, the camera and microphone will not work and will display this error message instead. Solving this problem is very basic and you can do it in a minute or two. Fix 1 – Provide Camera, Microphone Permissions You can provide the necessary camera and microphone permissions directly in settings. Step 1 – Go to the Settings tab. Step 2 – Open the Privacy & Security panel. Step 3 – Turn on the “Camera” permission there. Step 4 – Inside, you will find a list of apps that have requested permission for your phone’s camera. Step 5 – Open the “Camera” of the specified app

According to news on April 17, HMD teamed up with the well-known beer brand Heineken and the creative company Bodega to launch a unique flip phone - The Boring Phone. This phone is not only full of innovation in design, but also returns to nature in terms of functionality, aiming to lead people back to real interpersonal interactions and enjoy the pure time of drinking with friends. Boring mobile phone adopts a unique transparent flip design, showing a simple yet elegant aesthetic. It is equipped with a 2.8-inch QVGA display inside and a 1.77-inch display outside, providing users with a basic visual interaction experience. In terms of photography, although it is only equipped with a 30-megapixel camera, it is enough to handle simple daily tasks.

According to news on July 12, the Honor Magic V3 series was officially released today, equipped with the new Honor Vision Soothing Oasis eye protection screen. While the screen itself has high specifications and high quality, it also pioneered the introduction of AI active eye protection technology. It is reported that the traditional way to alleviate myopia is "myopia glasses". The power of myopia glasses is evenly distributed to ensure that the central area of sight is imaged on the retina, but the peripheral area is imaged behind the retina. The retina senses that the image is behind, promoting the eye axis direction. grow later, thereby deepening the degree. At present, one of the main ways to alleviate the development of myopia is the "defocus lens". The central area has a normal power, and the peripheral area is adjusted through optical design partitions, so that the image in the peripheral area falls in front of the retina.

According to news on April 3, Taipower’s upcoming M50 Mini tablet computer is a device with rich functions and powerful performance. This new 8-inch small tablet is equipped with an 8.7-inch IPS screen, providing users with an excellent visual experience. Its metal body design is not only beautiful but also enhances the durability of the device. In terms of performance, the M50Mini is equipped with the Unisoc T606 eight-core processor, which has two A75 cores and six A55 cores, ensuring a smooth and efficient running experience. At the same time, the tablet is also equipped with a 6GB+128GB storage solution and supports 8GB memory expansion, which meets users’ needs for storage and multi-tasking. In terms of battery life, M50Mini is equipped with a 5000mAh battery and supports Ty

At work, ppt is an office software often used by professionals. A complete ppt must have a good ending page. Different professional requirements give different ppt production characteristics. Regarding the production of the end page, how can we design it more attractively? Let’s take a look at how to design the end page of ppt! The design of the ppt end page can be adjusted in terms of text and animation, and you can choose a simple or dazzling style according to your needs. Next, we will focus on how to use innovative expression methods to create a ppt end page that meets the requirements. So let’s start today’s tutorial. 1. For the production of the end page, any text in the picture can be used. The important thing about the end page is that it means that my presentation is over. 2. In addition to these words,
