Home  >  Q&A  >  body text

How can I first show the syntax for logging into the system when I type a folder name in localhost

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

P粉351138462P粉351138462173 days ago358

reply all(2)I'll reply

  • P粉529245050

    P粉5292450502024-04-03 12:54:01

    If the user is not logged in, check the cookie/session and redirect to the login page.

    If login is not mandatory but you want to ensure the user sees the login page, create a session that is started in the login page. And check if the session exists on other pages and then redirect

    reply
    0
  • P粉463840170

    P粉4638401702024-04-03 11:38:11

    First, if your web application allows user authentication, do so.

    On a page you don't want unauthenticated users to access, add this code to the top of your code script, for example profile.php

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

    Then, add this code snippet on the login page.

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

    reply
    0
  • Cancelreply