0

SQL テーブルの「subscription_expires」列をチェックするクエリをログインに追加しようとしています。これは基本的に、ユーザーのメンバーシップの有効期限が切れているかどうかを確認し、日付が現在の日付 + である場合、別のページにリダイレクトする必要がありますか?

これが私のコードですが、subscription_expires の日付が現在の日付であるかどうかを確認する方法がわかりません +

誰かが私にこれを行う方法を教えてもらえますか? ありがとう。

// Check database to see if email and the hashed password exist there.
            $query = "SELECT id, email, close_account ";
            $query .= "FROM ptb_users ";
            $query .= "WHERE email = '{$email}' ";
            $query .= "AND password = '{$hashed_password}' ";
            $query .= "AND close_account = '0' ";
            $query .= "LIMIT 1";
            $result_set = mysql_query($query);
            confirm_query($result_set);
            if (mysql_num_rows($result_set) == 1) {
                // email/password authenticated
                // and only 1 match
                $found_user = mysql_fetch_array($result_set);
                $_SESSION['user_id'] = $found_user['id'];
                $_SESSION['email'] = $found_user['email'];
                $_SESSION['sub_expires'] = $found_user['subscription_expires'];
                $_SESSION['logged_in'] = true;

                $result = mysql_query("UPDATE ptb_users SET user_online='Online' WHERE id=".$_SESSION['user_id']."") 
or die(mysql_error());



                redirect_to("dashboard.php");
4

3 に答える 3

0

あなたはこのように試すことができます-(where条件でsubscription_expireを追加しました)

// Check database to see if email and the hashed password exist there.
            $query = "SELECT id, email, close_account ";
            $query .= "FROM ptb_users ";
            $query .= "WHERE email = '{$email}' ";
            $query .= "AND password = '{$hashed_password}' ";
            $query .= "AND close_account = '0' ";
            $query .= "AND subscription_expires < now() ";
            $query .= "LIMIT 1";

「subscription_expires」はタイムスタンプ/日時フィールドであると想定しています。

于 2013-01-03T15:06:35.717 に答える
0

これは、保存された時間に基づいてリダイレクトを実行するために必要なロジックです。

PHP

// If you store a timestamp
$sub_time = $found_user['subscription_expires'];

// If you store a string date time
$user_time = new DateTime($found_user['subscription_expires']);
$sub_time = $user_time->format("U");

if($sub_time <= time())
{
    // Assuming this function works
    redirect_to("mypage.php");
}

説明した

保存された UNIX タイムスタンプと保存された日時の両方のツールを提供しました。基本的に、サブスクリプション時間が現在の時間以下であること (つまり、有効期限が切れていること) を検証し、リダイレクト機能を使用してそれらを送信します。

于 2013-01-03T15:13:09.520 に答える
0

リダイレクト関数が何で構成されているかはわかりませんが、 header() を使用してユーザーをリダイレクトすることができます。

このコード:

$_SESSION['sub_expires'] = $found_user['subscription_expires'];
$_SESSION['logged_in'] = true;

は次のように置き換えられます。

$_SESSION['sub_expires'] = $found_user['subscription_expires'];

if($_SESSION['sub_expires'] <= time()){
    header('Location: login.php');
    exit();
}else{
    $_SESSION['logged_in'] = true;
}

この変更により、有効期限が現在の時間以下の場合、ユーザーがリダイレクトされ、ページが終了します。それ以外の場合、ユーザーはまだログインしているため、それに応じて続行し、logged_inセッション変数を設定します。

于 2013-01-03T15:21:32.463 に答える