php - Session redirect loop on login page work-around advice -


i looking placing code above in header.php include.

the first few lines of header has :

<?php session_start(); if(!isset($_session["loggedin"])){ header("location: login.php"); exit;} ?> 

the unfortunate consequence of when user gets redirected login.php hit redirect loop.

would best way forward creating if statement along lines of pseudo:

if (page="login.php") {   //do not redirect login.php } 

before session_start();?

you can wrap code

if(!isset($_session["loggedin"])){ header("location: login.php"); exit;} 

in function such as:

function ensureloggedin() {   if (!isset($_session["loggedin"]))   {     header("location: login.php");     exit;   } } 

then call function pages authentication required.

such calling function on secretpage.php redirect login.php if user not logged in.

login.php should not have function.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -