<?php

    require_once("config/configDB.php"); 
    session_start();

    date_default_timezone_set('asia/kolkata');

    $user_id = $_SESSION['user_id'];
    $sql_update = "UPDATE user_login SET loggin_status=2, session_code='' WHERE id='$user_id' ";

    mysqli_query($conn,$sql_update);

    
    $ip  = mysqli_real_escape_string($conn, $_SERVER['REMOTE_ADDR']);
    //$users = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));$users->city;

    $useragent  = mysqli_real_escape_string($conn,$_SERVER['HTTP_USER_AGENT']);

    $ldend    = date("Y-m-d H:i:s");

    $userid     =  $_SESSION['user_id'];

    $session_code =  $_SESSION['session_code'];

    $sql_backend  = "INSERT INTO login_details(login_date_end, ip, useragent,userid,session_code ) VALUES ('".$ldend."','".$ip."','".$useragent."','".$userid."','".$session_code."')";
    mysqli_query($conn, $sql_backend);   

    
    
    mysqli_close($conn);


    
    session_destroy();
    
    unset($_SESSION['username'], $_SESSION['loggedin_time'],$_SESSION['user_id'],$_SESSION['login_status']);

    $url = "index.php";

	header("Location:$url");
    
?>