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 ?