<?php
session_start();
require_once realpath(dirname(__DIR__, 3) . '/services/Model.php');
$obj = new Model();

$userid = $_SESSION['userid'] ?? null;

//  Safe check
$checkIp = $_POST['ip'] ?? '';

if ($checkIp === '') {
    echo 'invalid';
    exit;
}

// Query
$result = $obj->rawSqlSingle(
    "SELECT COUNT(*) AS total FROM re_tbl_agent WHERE ip = '$checkIp' AND entry_by = '$userid'"
);

if ($result['total'] == 0) {
    echo 1; 
} else {
    echo 0; 
}
exit;