How to on load page destroy user session and force user log out?

  javascript, mysql, php

I have a part of the code where the user is allowed to use the services from the site as long as he pays the subscription after the subscription expires he has 10 days to pay, after 10 days from the day the subscription expires his account is suspended.

The problem is that only when the user logs out and tries to log in he see that his account has been suspended.

now I need to add on this existing code that during the load page destroy user session if the user has expired 10 days after not paying the subscription.

most of the code is already made I just need where to put and which code exactly to use to destroy user session on page load and to log out user:

The code:

if ($user->expire_date == null) {
        echo "<script>window.location.href ='/payment.php';</script>";
        $extendExpiredDate = date("Y-m-d", strtotime($user->expire_date ." +10 days") );
        $todayDate = Date('Y-m-d');
        if ($todayDate > $extendExpiredDate) {
            echo "<script>window.location.href ='/payment.php';</script>";

Source: Ask PHP