0

我有一个有用户的网站。每个用户帐户在 mysql 表中都有一个到期日期subscription_expires

有没有办法将用户重定向到dashboard.php以外的另一个页面,如果他们的个人资料或在尝试登录后表示他们的个人资料已过期的今天日期subscription_expires=

我尝试过使用sub_expires等,但如果用户的个人资料过期,它仍然会登录用户。

这是我的登录脚本:

<?php

    if (logged_in()) {
        redirect_to("dashboard.php");
    }

    include_once("includes/form_functions.php");

    // START FORM PROCESSING
    if (isset($_POST['submit'])) { // Form has been submitted.
        $errors = array();

        // perform validations on the form data
        $required_fields = array('email', 'password');
        $errors = array_merge($errors, check_required_fields($required_fields, $_POST));

        $fields_with_lengths = array('email' => 30, 'password' => 30);
        $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));

        $email = trim(mysql_prep($_POST['email']));
        $password = trim(mysql_prep($_POST['password']));
        $hashed_password = md5($password);

        if ( empty($errors) ) {
            // 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'];

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


                redirect_to("dashboard.php");
            } else {
                // email/password combo was not found in the database
                $message = "<div class=\"infobox\"><strong>Email/Password combination incorrect.</strong><br />
                    Please make sure your caps lock key is off and try again.</div>";
            }

                } else {
            if (count($errors) == 1) {
                $message = "<div class=\"infobox\">There was 1 error in the form.<div>";


            } else {
                $message = "<div class=\"infobox\">There were " . count($errors) . " errors in the form.<div>";
            }
        }


    } else { // Form has not been submitted.
        if (isset($_GET['logout']) && $_GET['logout'] == 1) {
            $message = "<div class=\"infobox\">You are now logged out.</div>";
        } 
        $email = "";
        $password = "";
    }
?>
            <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
            <?php if (!empty($errors)) { display_errors($errors); } ?>
            <form action="login.php" method="post">

Email<br />
<input name="email" type="text" value="<?php echo htmlentities($email); ?>" size="40" maxlength="50" />

  <br />
  <br />
  Password<br />
  <input name="password" type="password" value="<?php echo htmlentities($password); ?>" size="40" maxlength="30" />

  <br />
  <br />
<input type="submit" name="submit" value="Login" />


            </form>
4

2 回答 2

0

您没有在选择查询中包含“subscription_expires”字段。所以你将得到 $_SESSION['sub_expires'] 的空值。此外,我在您的逻辑中看不到任何地方尝试使用 $_SESSION['sub_expires'] 值来做任何有意义的事情,例如阻止用户登录。您只是自动更新您的 ptb_users 表以将它们显示为在您甚至对该值进行任何检查之前在线。

于 2012-11-06T20:43:20.070 回答
0

您也在使用该'{$hashed_password}'参数,但没有设置它(而是设置trim(mysql_prep($_POST['password']))。该查询几乎可以肯定永远不会返回一个值......

于 2012-11-06T20:55:03.803 回答