Show specific content only on the domain home page to unsigned users

49 views Asked by At

I need to display the login form located in the external php file common for all pages of the site only on the homepage which may look like www.domain.com, www.domain.com/ or www.domain.com/index.php, to unsigned visitors only.

I've made the following code to put before the braces:

if(!isset($_SESSION["session"])
and
$_SERVER['REQUEST_URI'] === '/index.php'
or
$_SERVER['REQUEST_URI'] === '/')

but while it obeys URI rules and hides the form on secondary pages it still shows the login form to signed in visitors on the home page.

And I'm sure there should be other glitches.

What have I missed?

1

There are 1 answers

0
Nur Muhammad On BEST ANSWER

I think you must put OR condition in a brackets.

So, it must be:

if (
  !isset($_SESSION["session"]) and 
  ($_SERVER['REQUEST_URI'] === '/index.php' or $_SERVER['REQUEST_URI'] === '/')
) {
  // Your code
}