到期系统Php

时间:2017-12-11 15:03:01

标签: php mysqli count

我们的系统存在问题。我不知道如何以及从何处开始将代码放入系统中。该过程是在卖家注册他/她的帐户后开始计算30天,30天后卖家帐户中会有一个弹出通知告知已经过期。我也尝试通过互联网搜索教程但它只是让我感到困惑。希望能帮助并摆脱它。谢谢:)顺便说一下,请问mysqli。

这是卖家检查用户是否有效的代码:

   <?php
session_start();

?>
<?php
include("db_connection.php");

$s_username = $_POST['s_username'];
$s_password= sha1($_POST['s_password']);

//check user if exist
$check_query = mysqli_query($db, "SELECT * FROM seller WHERE s_username = '$s_username' AND s_password = '$s_password'");
$count = mysqli_num_rows($check_query);

if($count == 1)
{
    session_start();
    while($result = mysqli_fetch_array($check_query))
    {
        $_SESSION['seller_id'] = $result['seller_id'];
        $_SESSION['s_fname'] = $result['s_fname'];
        $_SESSION['s_username'] = $result['s_username'];
        $_SESSION['s_user_type'] = $result['s_user_type'];
        $_SESSION['s_status'] = $result['s_status'];
    }

    header('location: Seller/seller_home.php');
}else if($count>1){
    echo "Error logging in...<br>Please contact administrator";
}else{
    header('location: index.php');
}
?>

**我应该在哪里开始使用代码到期? *

1 个答案:

答案 0 :(得分:0)

你可以这样做的一种方法可能如下。

$maxdays=30;
$now=new DateTime( 'now' );


/*
    other code...
*/


while( $result = mysqli_fetch_array( $check_query ) ) {
    $id=$result['seller_id'];
    $forename=$result['s_fname'];
    $username=$result['s_username'];
    $type=$result['s_user_type'];
    $status=$result['s_status'];
    $joindate=$result['date_joined'];
}

$joindate=new DateTime( $joindate );
if( $now->diff( $joindate )->days > $maxdays ){
    /* bad foo - account exired ~ process account expiry somehow */

    $difference = abs( $now->diff( $joindate )->days - $maxdays );

} else {

    $_SESSION['seller_id'] = $id;
    $_SESSION['s_fname'] = $forename;
    $_SESSION['s_username'] = $username;
    $_SESSION['s_user_type'] = $type;
    $_SESSION['s_status'] = $status;

    header('Location: seller/seller_home.php');
}