Syntax error in conditional statement

Hello, I’m confused about the operators…
Here is the code:

echo "<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>";
$letters = "../letters.dat";
$data    = @file($letters);
$data    = @array_reverse($data);
$ncol    = count($data);
$ip      = $_SERVER['REMOTE_ADDR'];
$file    = "ips.dat";
$ban     = file($file);
$count   = count($ban);
for ($i = 0; $i < $count; $i++) {
    if ($ip == $ban[$i]) {
        echo " ";
    }} else {
        if (file_exists($letters)) {
            for ($j = 0; $j < $ncol; $j++) {
                list($login, $photo, $message, $time) = split(":::", "$data[$j]");
                echo "<table width='100%' class='message'>
    <tr><td><img src=$photo width='50' height='50'>&nbsp;$login</td><td width='50'>$time</td></tr>
    <tr><td colspan='2'>$message</td></tr></table>";
        } else {
            echo "<center><font color='silver'><h1> </h1></font></center>";

I need to make it so that when $ip == $ban[$i]“You are banned” is displayed, and if it is false, then such statements are displayed , which start with if (file_exists($letters))… Please tell me.

Answer 1, authority 100%

Let me first suggest some importantpoints, in my opinion.
Instead of $_SERVER['REMOTE_ADDR']try using $_SERVER['HTTP_X_FORWARDED_FOR'], sometimes it helps in displaying real ip, not proxy.

Also note that:

for ($i=0; $i<$count; $i++){ if($ip ==
 $ban[$i]){ echo " ";}} else

elsewon’t work because extra curly brace.

Answer 2

IMHO this block makes sense

$count = count($ban);
for ($i=0; $i<$count; $i++){
if($ip == $ban[$i]){
echo " ";}}

replace with a simpler design

if (in_array($ip, $ban))
    echo " ";

else goes further

Answer 3

The parenthesis is not superfluous, just elseis NOT after if, but after for.