2012-11-06 2 views
0

사용자가있는 사이트가 있습니다. 각 사용자 계정의 유효 기한은 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> 
+0

일부 다른 일반적인 사항 :. 사용 배타적 상한선 범위와 (그래서, ''<''), 특히 날짜/시간/타임 스탬프 값을 처리 할 때, 그리고 웹상에서 더욱 그렇습니다. 당신은 준비된 문장을 사용하지 않습니다. SQL 인젝션. 또한 암호에 MD5 해시를 사용하고 있습니다.이 암호는 일종의 고유 한 소금을 사용하지 않고 쉽게 분해 할 수 있습니다. –

답변

0

:

여기 내 로그인 스크립트입니다. 그래서 당신은 $ _SESSION [ 'sub_expires']에 대해 null을 얻을 것입니다. 또한, 사용자가 로그인하는 것을 막는 것과 같은 의미있는 작업을 수행하기 위해 $ _SESSION [ 'sub_expires'] 값을 사용하려는 로직이 어디에도 표시되지 않습니다. ptb_users 테이블을 자동으로 업데이트하여 다음과 같이 표시합니다. 온라인으로 당신이 그 가치에 어떤 점검을하기조차하기 전에.

0

또한 (당신이 trim(mysql_prep($_POST['password'])) 대신 그 쿼리가 거의 확실하게 값을 반환하지 설정을 설정하지 않고 '{$hashed_password}' 매개 변수를 사용하는 ...

관련 문제