I have the following PHP code which counts every access to the page. If I call the side direct it counts certain. If I make a Ajax call it starts always again with 1.
<?php
session_start();
header('Access-Control-Allow-Origin: *');
if (!isset($_SESSION['zaehler'])) {
$_SESSION['zaehler'] = 1;
} else {
$_SESSION['zaehler']++;
}
echo $_SESSION['zaehler'];
?>
I understand that an ajax call is the same like an direct call by reading this: Do AJAX requests retain PHP Session info? How can I count each ajaxCall as long as the side is open?
I'm doing a simple jquery ajaxCall:
$.get( "http://www.huntinggrounds.de/aa.php", function( data ) {
console.log( "dataResponse: ", data );
}) .fail(function(jqXHR, textStatus ) {
console.log( "error",textStatus);
})
.always(function() {
console.log( "finished" );
});
I made test-files, testfile.html, just a black screen. Click on desktop and see the counter in your console the php-file is here.