사용자가있는 사이트가 있습니다. 각 사용자 계정의 유효 기한은 mysql 테이블 subscription_expires
입니다.만료 날짜 = 오늘 날짜 인 경우 페이지로 리디렉션 하시겠습니까?
프로필이 만료되었다고 말한 로그인 시도 후 오늘 날짜까지 subscription_expires
이 =
일 경우 사용자를 dashboard.php가 아닌 다른 페이지로 리디렉션 할 수 있습니까?
나는 sub_expires
등을 사용하여 이동을 시도했지만 운이 좋지는 않지만 프로필이 만료 된 경우에도 사용자를 기록합니다. 당신은 당신의 선택 쿼리에서 "subscription_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>
일부 다른 일반적인 사항 :. 사용 배타적 상한선 범위와 (그래서, ''<''), 특히 날짜/시간/타임 스탬프 값을 처리 할 때, 그리고 웹상에서 더욱 그렇습니다. 당신은 준비된 문장을 사용하지 않습니다. SQL 인젝션. 또한 암호에 MD5 해시를 사용하고 있습니다.이 암호는 일종의 고유 한 소금을 사용하지 않고 쉽게 분해 할 수 있습니다. –