I have one script that works via mysql and php. Now I have a problem, namely if the user does not pay the monthly subscription, it is necessary after 10 days from the day of the invoice creation to suspend the user’s account but the problem is:
the user account is suspended only after the user is log out of the client area, I need the user account to be suspended immediately while it is still logged.
I need this because if the user’s account is not suspended while logged in then he can use the services for free as long as he is logged in.
These are parts of the code from the two scripts for the user suspend account, if it is possible to add some part of the code so that the user is suspended immediately after 10 days not paying the invoice and not only after log out.
<?php $todayDate = Date('Y-m-d'); $extendExpiredDate = date("Y-m-d", strtotime($user->expire_date ." +10 days")); if ($todayDate < $extendExpiredDate && $user->is_active != 2) { ?> <li><a href="<?php HREF('/upload-file.php'); ?>"><i class="fa fa-circle-o text-red"></i> <span>Upload</span></a></li> <li><a href="<?php HREF('/list.php'); ?>"><i class="fa fa-circle-o text-yellow"></i> <span>List Uploaded </span></a></li> <li><a href="<?php HREF('/translate.php'); ?>"><i class="fa fa-circle-o text-blue"></i> <span>Translate </span></a></li> <li><a href="<?php HREF('/converter.php'); ?>"><i class="fa fa-circle-o text-green"></i> <span>Convert </span></a></li> <li><a href="<?php HREF('/display.php'); ?>"><i class="fa fa-circle-o text-green"></i> <span>search</span></a></li> <?php } ?> <?php } ?>
function db_getUserActiveStatus($id) { $userdb = new ezSQL_mysqli(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); $usersql = "SELECT is_active FROM tbl_users WHERE id = %s;"; $userquery = $userdb->prepare($usersql,$id); $userStatus = $userdb->get_row($userquery); $suspendUser = $userStatus->is_active != 2 ? 2 : 1; return $suspendUser; } function db_suspendUser($id) { $status = db_getUserActiveStatus($id); $db = new ezSQL_mysqli(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); $sql = "UPDATE tbl_users SET is_active=%d WHERE id=%s"; $query = $db->prepare($sql, $status, $id); $db->query($query); return $db->rows_affected; }
Advertisement
Answer
Make every page load verify the logged in user. When the user is suspended, the next time he or she attempts to load a page, he or she will be locked out.