forked from phamtienthanh-luvina/samforum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
track_clicks_class.php
40 lines (31 loc) · 1.22 KB
/
track_clicks_class.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
<?PHP
class Click{
protected $conn;
function __construct($conn){
$this->IP = $_SERVER["REMOTE_ADDR"];
$this->conn = $conn;
}
function store_clicks(){
$create_table_query = $this->conn->prepare("CREATE TABLE IF NOT EXISTS click(
user_ip varchar(30) not null,
clicked_times int(11) not null,
primary key(user_ip)
)");
if(!$create_table_query->execute()){
echo "<p> table to store hits couldn't be created </p>";
}
$select_ip = $this->conn->prepare("SELECT user_ip FROM click WHERE user_ip = :user_ip");
$select_ip->execute(array(':user_ip'=>$this->IP));
$select_ip = $select_ip->fetch(PDO::FETCH_ASSOC);
$insert_ip_query = $this->conn->prepare("insert into click set user_ip = :user_ip, clicked_times = 1");
$insert_ip_query->execute(array('user_ip'=>$this->IP));
$update_existing_info = $this->conn->prepare("UPDATE click SET clicked_times = clicked_times + 1 WHERE user_ip = :user_ip ");
$update_existing_info->execute(array(':user_ip'=>$this->IP));
}
function show_hits_amount(){
$query_hits = $this->conn->prepare("select * FROM click");
$query_hits->execute();
echo "</br>" . "<b> Total unique hits: </b>" . $query_hits->rowCount();
}
}
?>