After Login, My index.php redirects to Login.php

i have used this code for years and never experienced this, using a new hosting service prior to the ones i have always used and am getting this issue.

        session_start();

$rec_page = $_SERVER['REQUEST_URI'];

$cPage = $_SERVER['PHP_SELF'];

if(!isset($_SESSION['isadmin'])){
    header('location: login.php?l=i');
}

include('includes/constants.php');
include('includes/functions.php');

$admin_login = $_SESSION['login'];
$admin_psw = GetAdminInfo($admin_login,'1');


if(isset($_REQUEST['cmd'])){
    if($_REQUEST['cmd']=="logout"){
        session_destroy();
        header('location: login.php');
    }
        }

this is the section of the code with the issues, once i login i get redirected to the login.php if i delete this

`if(!isset($_SESSION['isadmin'])){
header('location: login.php?l=i');
}`

i can login successfully but if i click on another page i will have to login again, so im guessing its a Session problem.

here is the action php for the login.php

        <?php

include('../includes/constants.php');
include('../includes/functions.php');

if(isset($_POST['xin'])){

    $ikey = addslashes($_POST['textKey']);
    $nkey = addslashes($_POST['textname']);
    $mysqli = mysqli_connect($dbserver,$dbuser,$dbpass) or die('Cannot connect to db');
    mysqli_select_db($mysqli, $db_db) or die('Cannot select db');
    
    $result=mysqli_query($mysqli, "SELECT * FROM admins WHERE login = '".$ikey."' && adminname = '".$nkey."'");
    $cnt = mysqli_num_rows($result);
    if($cnt > 0){
        while($rw=mysqli_fetch_array($result)){
            session_start();
            $_SESSION['isadmin']=true;
            $_SESSION['login'] = $ikey;
            $_SESSION['adminname'] = $nkey;
            header('location: ../index.php?cm='.$_SESSION['isadmin']);
        }
    }else{
        header('location: ../login.php?err=1'.mysqli_error($mysqli));
    }
    mysqli_close($mysqli);
}

?>

1 answer

  • answered 2022-05-04 10:25 Saheed

    use javascript instead of header. No long story

    echo "<script>parent.self.location='index.php';</script>";
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum