How can PHP developers effectively handle user IPs for tracking purposes without relying on cookies?

One way PHP developers can effectively handle user IPs for tracking purposes without relying on cookies is by using session variables to store and track the user's IP address. This can be achieved by storing the user's IP address in a session variable when they first visit the website, and then checking and updating this variable as needed throughout their session.

// Start or resume the session
session_start();

// Check if the user's IP address is already stored in the session
if(!isset($_SESSION['user_ip'])) {
    // If not, store the user's IP address in a session variable
    $_SESSION['user_ip'] = $_SERVER['REMOTE_ADDR'];
}

// Update the user's IP address in the session if it has changed
if($_SESSION['user_ip'] != $_SERVER['REMOTE_ADDR']) {
    $_SESSION['user_ip'] = $_SERVER['REMOTE_ADDR'];
}