Click here to Skip to main content
15,918,624 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i tried to make an api like, but it always outputs N when i access
whereas if I access its work, whats wrong?

$_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);
$data = explode("\n", $data);
return $data;
$ips = get_data("ips");
echo (in_array($_GET['ip'], $ips)) ? 'Y' : 'N';

What I have tried:

note get_data = array like 123,, etc
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