Skip to content

Commit

Permalink
Counter file now contains extended information.
Browse files Browse the repository at this point in the history
  • Loading branch information
SCP002 committed Mar 6, 2018
1 parent b390438 commit 46d1ba1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions php/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Counter

private $jsonWrapper = null;
private $clientIp = null;
private $currentTime = null;

private $clientId = null;
private $sessionId = null;
Expand All @@ -25,6 +26,7 @@ public function __construct($clientId, $sessionId, $expireTime, $fileName, $time

$this->jsonWrapper = new JsonWrapper();
$this->clientIp = Utils::getClientIpAddress();
$this->currentTime = time();

$this->clientId = $clientId;
$this->sessionId = $sessionId;
Expand Down Expand Up @@ -64,7 +66,9 @@ private function processDailyAndTotal()
$currentDay = intval(date("d"));

$currentUserData = array(
"visitTime" => $this->currentTime,
"sessionId" => $this->sessionId,
"clientId" => $this->clientId,
"clientIp" => $this->clientIp
);

Expand Down Expand Up @@ -95,11 +99,12 @@ private function processDailyAndTotal()
private function processNow()
{
$clientIdExist = false;
$currentTime = time();
$expires = $currentTime + $this->expireTime;
$expires = $this->currentTime + $this->expireTime;

$currentUserData = array(
"expires" => $expires,
"visitTime" => $this->currentTime,
"sessionId" => $this->sessionId,
"clientId" => $this->clientId,
"clientIp" => $this->clientIp
);
Expand All @@ -109,7 +114,7 @@ private function processNow()
$clientIdExist = true;

$this->fileContents["now"]["users"][$user]["expires"] = $expires;
} else if ($currentTime >= $data["expires"]) {
} else if ($this->currentTime >= $data["expires"]) {
unset($this->fileContents["now"]["users"][$user]);
}
}
Expand All @@ -129,14 +134,18 @@ private function createFile()
"now" => array(
"users" => array(
// "expires" => "SESSION_EXPIRE_TIME",
// "visitTime" => "LAST_VISIT_TIME",
// "sessionId" => "SESSION_ID",
// "clientId" => "CLIENT_ID",
// "clientIp" => "CLIENT_IP"
)
),
"daily" => array(
"day" => intval(date("d")),
"users" => array(
// "visitTime" => "LAST_VISIT_TIME",
// "sessionId" => "SESSION_ID",
// "clientId" => "CLIENT_ID",
// "clientIp" => "CLIENT_IP"
)
),
Expand Down

0 comments on commit 46d1ba1

Please sign in to comment.