What is the best way to track and store information about which pages are being accessed in a PHP application?

One way to track and store information about which pages are being accessed in a PHP application is to use a database to store this information. You can create a table in the database to log each page access with details such as the page URL, timestamp, and any other relevant information. Then, you can insert a record into this table each time a page is accessed in your PHP application.

// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "your_database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Get the current page URL
$page_url = $_SERVER['REQUEST_URI'];

// Insert a record into the page_access table
$sql = "INSERT INTO page_access (page_url, access_time) VALUES ('$page_url', NOW())";

if ($conn->query($sql) === TRUE) {
    echo "Record inserted successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

// Close the database connection
$conn->close();