Syntax on how can I show the login system first when I type the folder name in localhost

Issue

I don’t know what the syntax is? What I want to happen is that when I type localhost/farm-e-mart the first file that should show the login system. How can I do that?

Solution

Firstly if your web app permit user authentication, do this.

On the page, you don’t want unauthenticated user to have access to, add this code at the top of the code script e.g profile.php

session_start();
if(!isset($_SESSION){
   header("location:login.php");
}

Then, on the login page add this code snippet.

session_start();
if(isset($_SESSION){
header("location:profile.php");
}

Answered By – Gabriel J

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published