-
Notifications
You must be signed in to change notification settings - Fork 1
/
Model2.php
67 lines (67 loc) · 2.11 KB
/
Model2.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
<?php
function isolateDomain($url) {
return parse_url($url)['host'];
}
function newModel() {
if(isset($_COOKIE['uid'])) {
return $_COOKIE['uid'];
} else {
$uid = uniqid();
setcookie("uid", $uid, time()+631139040);
$dir = realpath(__DIR__ . '/../keys/models') . "/";
$file = fopen($dir.$uid.".txt", "w+");
$array = array();
fwrite($file, serialize($array));
return $uid;
}
}
function addNewCategory($catName) {
$dir = realpath(__DIR__ . '/../keys/models') . "/";
$model = fopen($dir . $_COOKIE['uid'] . ".txt", "r");
$array = unserialize(fgets($model));
fclose($model);
if(!array_key_exists($catName, $array)) {
$array[$catName]=array(array());
}
unset($array[$catName][0]);
$model = fopen($dir . $_COOKIE['uid'] . ".txt", "w+");
fwrite($model, serialize($array));
fclose($model);
return $_COOKIE['uid'];
}
function addNewDomain($catName, $domName) {
$dir = realpath(__DIR__ . '/../keys/models') . "/";
$model = fopen($dir . $_COOKIE['uid'] . ".txt", "r");
$array = unserialize(fgets($model));
fclose($model);
if(!array_key_exists($catName, $array)) {
addNewCategory($catName);
}
$array[$catName][$domName] = 0;
$model = fopen($dir . $_COOKIE['uid'] . ".txt", "w+");
fwrite($model, serialize($array));
fclose($model);
return $_COOKIE['uid'];
}
function increment($catName, $domName) {
$dir = realpath(__DIR__ . '/../keys/models') . "/";
$model = fopen($dir . $_COOKIE['uid'] . ".txt", "r");
$array = unserialize(fgets($model));
fclose($model);
if(!array_key_exists($domName, $array[$catName])) {
addNewDomain($catName, $domName);
}
$array[$catName][$domName] += 1;
$model = fopen($dir . $_COOKIE['uid'] . ".txt", "w+");
fwrite($model, serialize($array));
fclose($model);
return $_COOKIE['uid'];
}
function returnArray() {
$dir = realpath(__DIR__ . '/../keys/models') . "/";
$model = fopen($dir . $_COOKIE['uid'] . ".txt", "r");
$array = unserialize(fgets($model));
fclose($model);
return $array;
}
?>