Help. It is necessary to find out how many pages the user has viewed in one session and the time spent on these pages (except for the last).

The question with time is clear, you need to get the difference between the time of the first entry on the page and the last.

I do not really understand how to determine that the transition to another page has been made.

  • > and the time spent on these pages Bad news: browsers have invented tabs, so according to pure link navigation this estimate will be very inaccurate. - drdaeman


3 answers 3

<?php session_start(); if(!isset($_SESSION['page'][$_SERVER['REQUEST_URI']])){ $_SESSION['page'][$_SERVER['REQUEST_URI']] = 0; } $_SESSION['page'][$_SERVER['REQUEST_URI']]++; //--- //Получение общего числа страниц: print(array_sum($_SESSION['page'])); //Получение числа уникальных страниц: print(count($_SESSION['page'])); 

    I think you should try using Google Analytics and the reports it provides.

      There are several options:

      1. All links on the site you let through your own wrapper type <a href="goto.php?new_link=url">link</a> . And in goto.php write to the session and the time and to which pages the user goes, and then redirect to url.
      2. In the server code, scripts set, say, $link = "script_name" , insert a script that will write everything it needs to the session.