Question

When admin log in to the admin panel it should redirect him to the admin panel and the second time to not, but it always redirecting.

if($logedin_admin='1'){
    $logedin_admin=0;
    $_SESSION['is_admin']=1;
    header('Location: admin/index.php');
}

Can anyone tell me why?

I've made the if:

if(isset($logedin_admin) && $logedin_admin=='1'){
echo 'dsdasdas';
    $logedin_admin=0;
    $_SESSION['is_admin']=1;
    header('Location: admin/index.php');
    exit;
}

but it isn't redirecting and it isn't echoing dsdasdas

Was it helpful?

Solution

It should be if($logedin_admin=='1'){

You are doing an assignment operation instead of a comparison..

Also, make sure if the session was started...

The code..

<?php
session_start();   //<=--------- Add this
if($logedin_admin=='1'){
    $logedin_admin=0;
    $_SESSION['is_admin']=1;
    header('Location: admin/index.php');
    exit; //<=----------- Add an exit too.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top