Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i tried to make an api like https://blackbox.ipinfo.app/lookup/127.0.0.1, but it always outputs N when i access https://exampledomain.com/?ip=127.0.0.1
whereas if I access https://exampledomain.com/?ip=1234 its work, whats wrong?


<?php
session_start();
unset($_GET);
$_GET = array();
$p0 = explode('&',file_get_contents('php://input'));
foreach ($p0 as $key => $value)
{
$p1 = explode('=',$value);
$_GET[$p1[0]] = $p1[1];
}
function get_data($data) {
$data = file_get_contents("data/$data.dat");
if(strcasecmp(substr(PHP_OS, 0, 3), 'WIN') == 0){
$data = explode("\r\n", $data);
}else{
$data = explode("\n", $data);
}
return $data;
}
$ips = get_data("ips");
echo (in_array($_GET['ip'], $ips)) ? 'Y' : 'N';
exit;
?>


What I have tried:

note get_data = array like 123,1.2.3.4, etc
Posted
Updated 1-Feb-23 12:48pm

1 solution

so your data is comma-separated, but you are trying to explode using line separators like \r\n.
suggest you simply do a var_dump() of $data at a couple of points to see what you actually have in there.
Also in_array() expects strings, and you are working with numerics, so careful there!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900