Joe Bobby
Joe Bobby

Reputation: 2811

Checking Txt File for Visitors IP

I want my website to check if the current visitor's IP Address is or isn't in a text file and if it is I want to assign a value.

<?php
$list = file("checkip.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$listarray !== (in_array($_SERVER['REMOTE_ADDR'], $list));
if ( $listarray )
{
    $value = "IP NOT FOUND IN FILE";
}else{
    $value = "IP FOUND IN FILE";
    }?>

<?php echo $value ?>

I placed my ip address in the checkip.txt file and it ends up displaying "IP FOUND IN FILE"

I have tried testing = and !== for $listarray but still no luck

Upvotes: 0

Views: 657

Answers (1)

meda
meda

Reputation: 45490

Try this approach:

$list = file("checkip.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
var_dump($list);
if (in_array($_SERVER['REMOTE_ADDR'], $list) ){
    echo "IP FOUND IN FILE";
}else{
    echo "IP NOT FOUND IN FILE";
}

Upvotes: 1

Related Questions