-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpVisionApi.php
46 lines (42 loc) · 1.77 KB
/
phpVisionApi.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
<?php
require "phpVisionConfig.php";
function register_active_user() {
if(session_status() !== PHP_SESSION_ACTIVE) session_start();
if (isset($_SESSION["phpvision_has_registered"]) && $_SESSION["phpvision_has_registered"]) return;
$_SESSION["phpvision_has_registered"] = true;
$conn = new mysqli($GLOBALS["db_server_name"], $GLOBALS["db_username"], $GLOBALS["db_password"]);
mysqli_select_db($conn, "phpVision");
$stmt = $conn->prepare("INSERT INTO Events (Time, type) VALUES (NOW(), ?)");
$type = "activeUser";
$stmt->bind_param("s", $type);
$stmt->execute();
$conn->close();
}
function register_page_hit($path) {
$conn = new mysqli($GLOBALS["db_server_name"], $GLOBALS["db_username"], $GLOBALS["db_password"]);
mysqli_select_db($conn, "phpVision");
$stmt = $conn->prepare("INSERT INTO Events (Time, type, data) VALUES (NOW(), ?, ?)");
$type = "pageView";
$data = json_encode(array("page" => $path));
$stmt->bind_param("ss", $type, $data);
$stmt->execute();
$conn->close();
}
function register_custom_event($name, $info="") {
$conn = new mysqli($GLOBALS["db_server_name"], $GLOBALS["db_username"], $GLOBALS["db_password"]);
mysqli_select_db($conn, "phpVision");
$stmt = $conn->prepare("INSERT INTO Events (Time, type, data) VALUES (NOW(), ?, ?)");
$type = "custom";
$data = json_encode(array("name" => $name, "info" => $info));
$stmt->bind_param("ss", $type, $data);
$stmt->execute();
$conn->close();
}
function phpVision_auto_register($currentPath="") {
register_active_user();
trim($currentPath);
if ($currentPath == "") $currentPath = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
trim($currentPath);
register_page_hit($currentPath);
}
?>