Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP session does not work in sub directory & kills existing session

I have 3 environments for PHP.

  1. Local
  2. Staging
  3. Live

The issue is that when I calling session in sub directory after session_start() that gives error that headers are already sent & kills existing session. And If I do not start session then it gives error for Undefined variable _SESSION.

Session is working only in ROOT directory. but not work in Subdirectory.

This only occurs on Live Environment. This same code is working on Local & Staging but not on Live.

I don't know but this may be PHP configuration issue. Please guide me.

like image 565
Mayur Champaneria Avatar asked Mar 24 '26 02:03

Mayur Champaneria


1 Answers

Add session_start() at the beginning of your main page. Please ensure that if you are including some other file, session_start() is not defined there else error will display.

like image 94
Happy Coding Avatar answered Mar 26 '26 17:03

Happy Coding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!