Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
PhemcodeJay committed Nov 10, 2024
1 parent 3affdf8 commit 8ea670a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions subscription-plan.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php


// Include the configuration file
require_once 'config.php';



/**
* Update expired subscriptions based on end date.
* Update expired subscriptions based on the end date.
*
* @param PDO $db Database connection
*/
function updateExpiredSubscriptions($db) {
$currentDate = date("Y-m-d");
Expand All @@ -23,20 +22,20 @@ function updateExpiredSubscriptions($db) {
*
* @param int $userId User ID
* @param PDO $db Database connection
* @return bool True if active, false if expired
* @return bool True if the subscription is active, false if expired
*/
function isSubscriptionActive($userId, $db) {
$query = "SELECT status FROM subscriptions WHERE user_id = :userId";
$stmt = $db->prepare($query);
$stmt->bindParam(':userId', $userId);
$stmt->bindParam(':userId', $userId, PDO::PARAM_INT);
$stmt->execute();
$subscription = $stmt->fetch(PDO::FETCH_ASSOC);

return ($subscription && $subscription['status'] === 'active');
}

/**
* Handle user access control based on subscription status.
* Control user access based on subscription status.
*
* @param int $userId User ID
* @param PDO $db Database connection
Expand All @@ -54,7 +53,8 @@ function handleSubscriptionCheck($userId, $db) {
// Run the daily update to mark expired subscriptions
updateExpiredSubscriptions($db);

// Example usage for a user
$userId = 1; // Replace with the actual user ID
// Example usage for a specific user (replace $userId with actual user ID)
$userId = 1;
handleSubscriptionCheck($userId, $db);

?>

0 comments on commit 8ea670a

Please sign in to comment.