<?php
@session_start();
@ob_start();
@include('./includes/config.php'); 
@ob_clean();
if(isset($_POST['otp'])){
    $input_otp = intval(trim($_POST['otp']));

    if(isset($_SESSION['otp']) && intval($_SESSION['otp']) === $input_otp){
        $user_id = $_SESSION['otp_user_id'];
        $phone = $_SESSION['otp_phone'];
        mysqli_query($tng_conn, "UPDATE users SET login_token='$login_token', login_time='$login_time', is_login=1 WHERE id='$user_id'");

        $_SESSION['phone'] = $phone;
        $_SESSION['user_id'] = $user_id;
        $_SESSION['is_login'] = true;
        $_SESSION['login_token'] = $login_token;

        unset($_SESSION['otp']);
        unset($_SESSION['otp_phone']);
        unset($_SESSION['otp_user_id']);

        echo "success";
    } else {
        echo "failed";
    }
}
?>
