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