Search code examples
phpxampp

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


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");
    }