Score:0

in_array and isset are not working as expected

sa flag

i tried to make an api like https://blackbox.ipinfo.app/lookup/127.0.0.1 but it always outputs N when i access httpexampledomain.com/?ip=127.0.0.1 even though if i access httpexampledomain.com/?ip=123456 it can output "Y

<?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;
?>

noted : get_data = array like '123',1234,'1.2.3.4' etc

us flag
Why do you re-build the `$_GET` array in your code? I think half of your code is not needed and possible source for bugs. Also code would be much more readable if you wouldn't change the meaning of `$data` variable during processing.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.