I'm developing an analytics script that people will be able to add to their page in order to track visitor data. One of the issues I've come across is devising a way to track individual's sessions when they're viewing someone's page from a private browser (I.e. Incognito).
This is the script I'm using to see if someone to observe if someone has been active for more than 30 minutes, if they have, a new session will be created, if not, then they will resume their previous session.
session_start();
$max_time = 1800;
$current = time();
if (!isset ($_SESSION['Stationary'])){
$_SESSION['Stationary'] = time();
$session = $_SESSION['Stationary'];
}
if (!isset ($_SESSION['Inactive'])) {
$_SESSION['Inactive'] = time();
} else {
$session_life = $current - $_SESSION['Inactive'] ;
if ($session_life > $max_time ) {
session_destroy();
session_start();
$_SESSION['Inactive'] = time();
$_SESSION['Stationary'] = time();
$session = $_SESSION['Stationary'];
} else {
$_SESSION['Inactive'] = time();
$session = $_SESSION['Stationary'];
}
}
This script works flawlessly when a user views my page from a regular browser (IE. Chrome Incognito), however when they view it on something like an iPhone, in Private Browsing, every time they access a new page, a new session is rendered -- a problem that I do not have when viewed otherwise.
So my question then is, I'm aware that viewing pages in a Private Browser is achieved through temporary cacheing which is cleared once the browser is closed, however why is it that even when the browser is not closed, opening a link destroys their previous session even when the link leads to another page, with the same script on the page?
Is there a workaround to this?
EDIT:
I should note that this script is being placed in a php file with the header application/json
to be used as a JavaScript file as well.