Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot Redirect to the correct page using PHP session

In my application I have 4 roles. As per the roles, Users can view their access different pages. Currently I am maintaining 2 different sessions. $_SESSION['user_id'] and $_SESSION['role_id'].

My problem is, suppose we say the role_id =1 is Admin, role_id=2 is Doctor. If I logout from this session as Admin and logging as a Doctor to the site. Then I have click back button in web browser, it will redirect to the Admin page. I don’t want to redirect to the Admin page, just I want to remain in the same page.

Here I have used this codes to redirect but no working.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 //  redirect to main page according to the user role 
     if(isset($_SESSION['user_id']) && $_SESSION['role_id'] == 1){//admin
        header("location: index-2.php");
        exit;
     }

     if(isset($_SESSION['user_id']) && $_SESSION['role_id'] == 2){ // doctor
        header("location: index.php");
        exit;
     }
     
     if(isset($_SESSION['user_id']) && $_SESSION['role_id'] == 3){// lab
        header("location: index-lab.php");
        exit;
     }

     if(isset($_SESSION['user_id']) && $_SESSION['role_id'] == 4){// recep
        header("location: index-recep.php");
        exit;
     }

I don’t know where I went wrong. Could someone help me. Any help may highly appreciated.

>Solution :

As Cid mentioned, the cache is loaded when you click the back button. This isn’t something I’ve really tried, but you could try setting cache settings for your application to prevent the pages from being cached. See How do we control web page caching, across all browsers?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading