如何在php中为if语句添加多个条件

I'm working on a project in PHP. And in session.php I allow which users can access each page. Logged-in users and other. But the problem is that I can't add all the id-s from the table in my database to the if statement. Because I would like that all 'oglasi' should be accessible by all users.

        <?php
        include_once 'db.php';
        session_start();
        ob_start();

        $query = "SELECT id FROM oglasi";
        $result = mysqli_query($link, $query);

        while ($row = mysqli_fetch_array($result)) {
        $id = $row['id'];
        //if not logged in you can access
        if (empty($_SESSION['user_id']) &&
                $_SERVER['REQUEST_URI'] != '/SP/oglasi/index.php' &&
                $_SERVER['REQUEST_URI'] != '/SP/oglasi/registration.php' &&
                $_SERVER['REQUEST_URI'] != '/SP/oglasi/oglasi.php' &&
                $_SERVER['REQUEST_URI'] != '/SP/oglasi/oglasi_show.php?id='.$id &&
                $_SERVER['REQUEST_URI'] != '/SP/oglasi/user_insert.php' &&
                $_SERVER['REQUEST_URI'] != '/SP/oglasi/login_check.php') 
            header("Location: index.php");
            die();
        }
          }

        ?>

This is the key statement

    $_SERVER['REQUEST_URI'] != '/SP/oglasi/oglasi_show.php?id='.$id &&

$id variable should change 1,2... But it is not changeing.

If I do this it works, but it is not good if you have a lot of data.

    $_SERVER['REQUEST_URI'] != '/SP/oglasi/oglasi_show.php?id=2' &&
    $_SERVER['REQUEST_URI'] != '/SP/oglasi/oglasi_show.php?id=1' &&

Can someone help ?

I suppose you can simplify check this way:

include_once 'db.php';
session_start();
ob_start();

//if not logged in you can access
if (empty($_SESSION['user_id']) &&
    strpos($_SERVER['REQUEST_URI'], '/SP/oglasi/') !== 0) {
    header("Location: index.php");
    die();    
}

Here you check - if pattern /SP/oglasi/ not exists in your REQUEST_URI at position 0 (which means REQUEST_URI starts with it) - then you redirect user to index.php.

If not all oglasi subsections can be visited by user - you can still use your condition:

include_once 'db.php';
session_start();
ob_start();

if (empty($_SESSION['user_id']) &&
    $_SERVER['REQUEST_URI'] != '/SP/oglasi/index.php' &&
    $_SERVER['REQUEST_URI'] != '/SP/oglasi/registration.php' &&
    $_SERVER['REQUEST_URI'] != '/SP/oglasi/oglasi.php' &&
    $_SERVER['REQUEST_URI'] != '/SP/oglasi/user_insert.php' &&
    $_SERVER['REQUEST_URI'] != '/SP/oglasi/login_check.php' &&
    strpos($_SERVER['REQUEST_URI'], '/SP/oglasi/oglasi_show.php') !== 0  
) { 
    header("Location: index.php");
    die();
}