unieke-statistieken
-- database.php --
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?
if (!mysql_select_db("database_naam", mysql_connect("localhost", "dbuser", "dbpass")))
{
echo "geen database connectie.";
exit();
}
?>
if (!mysql_select_db("database_naam", mysql_connect("localhost", "dbuser", "dbpass")))
{
echo "geen database connectie.";
exit();
}
?>
-- mkstats.php --
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?
//-----------------------------//
// auth: Bas Kreleger //
// desc: unique ip adresses //
// file: mkstats.php //
//-----------------------------//
//-- require db connectie
require("database.php");
//-- set table
$stat_table = "statistieken";
//-- get ips from db
$cur_datum = date("d.m.Y");
$stat_sql = "SELECT ipaddrs,datum FROM " . $stat_table . " WHERE datum = '" . $cur_datum . "'";
$stat_res = mysql_query($stat_sql) or die(mysql_error());
//-- check for result
if (mysql_num_rows($stat_res) >= 1)
{
$stat_ipaddrs = mysql_result($stat_res, 0);
$stat_datum = mysql_result($stat_res, 0);
}
//-- set vars to create new record
else
$stat_empty = 1;
//-- check for result ip addrs
if (!$stat_empty)
{
//-- get single ip
$ipaddr = explode(",", $stat_ipaddrs);
//-- loop trough ips and match
for ($i = 0; $i < count($ipaddr); $i++)
{
if ($_SERVER['REMOTE_ADDR'] == $ipaddr[$i])
$norec = 1;
}
}
//-- no match, execute sql
if (!$norec)
{
//-- create new record
if ($stat_empty == 1)
$stat_sql = "INSERT INTO " . $stat_table . " (id,ipaddrs,datum) VALUES ('','" . $_SERVER['REMOTE_ADDR'] . "','" . $cur_datum . "')";
//-- update with new ip addr
else
{
$newips = $stat_ipaddrs . "," . $_SERVER['REMOTE_ADDR'];
$stat_sql = "UPDATE " . $stat_table . " SET ipaddrs = '" . $newips . "' WHERE datum = '$cur_datum'";
}
mysql_query($stat_sql) or die(mysql_error());
}
?>
//-----------------------------//
// auth: Bas Kreleger //
// desc: unique ip adresses //
// file: mkstats.php //
//-----------------------------//
//-- require db connectie
require("database.php");
//-- set table
$stat_table = "statistieken";
//-- get ips from db
$cur_datum = date("d.m.Y");
$stat_sql = "SELECT ipaddrs,datum FROM " . $stat_table . " WHERE datum = '" . $cur_datum . "'";
$stat_res = mysql_query($stat_sql) or die(mysql_error());
//-- check for result
if (mysql_num_rows($stat_res) >= 1)
{
$stat_ipaddrs = mysql_result($stat_res, 0);
$stat_datum = mysql_result($stat_res, 0);
}
//-- set vars to create new record
else
$stat_empty = 1;
//-- check for result ip addrs
if (!$stat_empty)
{
//-- get single ip
$ipaddr = explode(",", $stat_ipaddrs);
//-- loop trough ips and match
for ($i = 0; $i < count($ipaddr); $i++)
{
if ($_SERVER['REMOTE_ADDR'] == $ipaddr[$i])
$norec = 1;
}
}
//-- no match, execute sql
if (!$norec)
{
//-- create new record
if ($stat_empty == 1)
$stat_sql = "INSERT INTO " . $stat_table . " (id,ipaddrs,datum) VALUES ('','" . $_SERVER['REMOTE_ADDR'] . "','" . $cur_datum . "')";
//-- update with new ip addr
else
{
$newips = $stat_ipaddrs . "," . $_SERVER['REMOTE_ADDR'];
$stat_sql = "UPDATE " . $stat_table . " SET ipaddrs = '" . $newips . "' WHERE datum = '$cur_datum'";
}
mysql_query($stat_sql) or die(mysql_error());
}
?>
-- stats.php --
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?
//-----------------------------//
// auth: Bas Kreleger //
// desc: unique ip adresses //
// file: stats.php //
//-----------------------------//
//-- require db connectie
require("database.php");
//-- set table
$stat_table = "statistieken";
// post
if (!$_POST['submit'])
{
$dedatum = date('m.Y');
$smm = date('m');
$syy = date('Y');
}
else
{
$dedatum = $_POST['mm'] . "." . $_POST['yy'];
$smm = $_POST['mm'];
$syy = $_POST['yy'];
}
// get data
$sql = "SELECT ipaddrs,datum FROM " . $stat_table . " WHERE SUBSTRING(datum, 4, 7) = '" . $dedatum . "' ORDER BY id";
$res = mysql_query($sql);
// show form
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
echo "Selecteer een datum:<br>";
echo "<i>Toon statistieken van </i>";
echo "<select name=\"mm\">";
// januari
if ($smm == "01")
echo "<option value=\"01\" selected>Jan</option>";
else
echo "<option value=\"01\">Jan</option>";
// februari
if ($smm == "02")
echo "<option value=\"02\" selected>Feb</option>";
else
echo "<option value=\"02\">Feb</option>";
// maart
if ($smm == "03")
echo "<option value=\"03\" selected>Mar</option>";
else
echo "<option value=\"03\">Mar</option>";
// april
if ($smm == "04")
echo "<option value=\"04\" selected>Apr</option>";
else
echo "<option value=\"04\">Apr</option>";
// mei
if ($smm == "05")
echo "<option value=\"05\" selected>Mei</option>";
else
echo "<option value=\"05\">Mei</option>";
// juni
if ($smm == "06")
echo "<option value=\"06\" selected>Jun</option>";
else
echo "<option value=\"06\">Jun</option>";
// juli
if ($smm == "07")
echo "<option value=\"07\" selected>Jul</option>";
else
echo "<option value=\"07\">Jul</option>";
// augustus
if ($smm == "08")
echo "<option value=\"08\" selected>Aug</option>";
else
echo "<option value=\"08\">Aug</option>";
// september
if ($smm == "09")
echo "<option value=\"09\" selected>Sep</option>";
else
echo "<option value=\"09\">Sep</option>";
// oktober
if ($smm == "10")
echo "<option value=\"10\" selected>Okt</option>";
else
echo "<option value=\"10\">Okt</option>";
// november
if ($smm == "11")
echo "<option value=\"11\" selected>Nov</option>";
else
echo "<option value=\"11\">Nov</option>";
// december
if ($smm == "12")
echo "<option value=\"12\" selected>Dec</option>";
else
echo "<option value=\"12\">Dec</option>";
echo "</select> ";
echo "<select name=\"yy\">";
for ($i = 2003; $i <= 2030; $i++)
{
if ($syy == $i)
echo "<option value=\"" . $i . "\" selected>$i</option>";
else
echo "<option value=\"" . $i . "\">" . $i . "</option>";
}
echo "</select> ";
echo "<input type=\"submit\" value=\"tonen\" name=\"submit\">";
echo "</form><p>";
// show result or no result
echo "<table border=1 cellspacing=0 cellpadding=5>";
echo "<tr>";
echo "<th>url</th>";
echo "<th>views</th>";
echo "</tr>";
if (mysql_num_rows($res) >= 1)
{
while ($row = mysql_fetch_array($res))
{
$row[ipaddrs] = explode(",", $row[ipaddrs]);
$totips = count($row[ipaddrs]);
echo "<tr>";
echo "<td>" . $totips . "</td>";
echo "<td>" . $row['datum'] . "</td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"2\"><i>Er zijn geen statistieken bekend van </i><b>" . $dedatum . "</b>.</td></tr>";
}
echo "</table>";
?>
//-----------------------------//
// auth: Bas Kreleger //
// desc: unique ip adresses //
// file: stats.php //
//-----------------------------//
//-- require db connectie
require("database.php");
//-- set table
$stat_table = "statistieken";
// post
if (!$_POST['submit'])
{
$dedatum = date('m.Y');
$smm = date('m');
$syy = date('Y');
}
else
{
$dedatum = $_POST['mm'] . "." . $_POST['yy'];
$smm = $_POST['mm'];
$syy = $_POST['yy'];
}
// get data
$sql = "SELECT ipaddrs,datum FROM " . $stat_table . " WHERE SUBSTRING(datum, 4, 7) = '" . $dedatum . "' ORDER BY id";
$res = mysql_query($sql);
// show form
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
echo "Selecteer een datum:<br>";
echo "<i>Toon statistieken van </i>";
echo "<select name=\"mm\">";
// januari
if ($smm == "01")
echo "<option value=\"01\" selected>Jan</option>";
else
echo "<option value=\"01\">Jan</option>";
// februari
if ($smm == "02")
echo "<option value=\"02\" selected>Feb</option>";
else
echo "<option value=\"02\">Feb</option>";
// maart
if ($smm == "03")
echo "<option value=\"03\" selected>Mar</option>";
else
echo "<option value=\"03\">Mar</option>";
// april
if ($smm == "04")
echo "<option value=\"04\" selected>Apr</option>";
else
echo "<option value=\"04\">Apr</option>";
// mei
if ($smm == "05")
echo "<option value=\"05\" selected>Mei</option>";
else
echo "<option value=\"05\">Mei</option>";
// juni
if ($smm == "06")
echo "<option value=\"06\" selected>Jun</option>";
else
echo "<option value=\"06\">Jun</option>";
// juli
if ($smm == "07")
echo "<option value=\"07\" selected>Jul</option>";
else
echo "<option value=\"07\">Jul</option>";
// augustus
if ($smm == "08")
echo "<option value=\"08\" selected>Aug</option>";
else
echo "<option value=\"08\">Aug</option>";
// september
if ($smm == "09")
echo "<option value=\"09\" selected>Sep</option>";
else
echo "<option value=\"09\">Sep</option>";
// oktober
if ($smm == "10")
echo "<option value=\"10\" selected>Okt</option>";
else
echo "<option value=\"10\">Okt</option>";
// november
if ($smm == "11")
echo "<option value=\"11\" selected>Nov</option>";
else
echo "<option value=\"11\">Nov</option>";
// december
if ($smm == "12")
echo "<option value=\"12\" selected>Dec</option>";
else
echo "<option value=\"12\">Dec</option>";
echo "</select> ";
echo "<select name=\"yy\">";
for ($i = 2003; $i <= 2030; $i++)
{
if ($syy == $i)
echo "<option value=\"" . $i . "\" selected>$i</option>";
else
echo "<option value=\"" . $i . "\">" . $i . "</option>";
}
echo "</select> ";
echo "<input type=\"submit\" value=\"tonen\" name=\"submit\">";
echo "</form><p>";
// show result or no result
echo "<table border=1 cellspacing=0 cellpadding=5>";
echo "<tr>";
echo "<th>url</th>";
echo "<th>views</th>";
echo "</tr>";
if (mysql_num_rows($res) >= 1)
{
while ($row = mysql_fetch_array($res))
{
$row[ipaddrs] = explode(",", $row[ipaddrs]);
$totips = count($row[ipaddrs]);
echo "<tr>";
echo "<td>" . $totips . "</td>";
echo "<td>" . $row['datum'] . "</td>";
echo "</tr>";
}
}
else
{
echo "<tr><td colspan=\"2\"><i>Er zijn geen statistieken bekend van </i><b>" . $dedatum . "</b>.</td></tr>";
}
echo "</table>";
?>