1

I'm trying to create an api like https://blackbox.ipinfo.app/lookup/ to detect suspicious ip addresses, but my code is not up to expectations.

<?php
$ips = array('127.0.0.1', '30.121.111.2', '1.2.3.4', '123'); // SUSPICIOUS IP, HTTPS://example.com/?123 WORK BUT NOT FOR 127.0.0.1 ETC
foreach($ips as $badips)
{
    if (isset($_GET[$badips])) // CALL LIKE HTTPS://example.org/?1234
    {
        $blacklists = 'Y';
    }
}

if ($blacklists == "Y")
{
    echo "Y";
} else {
    echo "N";
}
?>

what's wrong with this code? when i call htttps://example.org/?1234 it outputs result ="Y" but when i call with https://example.org/?127.0.0.1 // etc it outputs "N" result

Phil
  • 157,677
  • 23
  • 242
  • 245
Dims
  • 11
  • 2
  • 2
    Why not use a named GET parameter? Also it'd perform better with `in_array`. so `htttps://example.org/?ip=1234` then `echo in_array($_GET['ip'], $ips)) ? 'Y' : 'N';` – user3783243 Jan 25 '23 at 02:45

0 Answers0