I have a weird problem. Which, I was using $_SESSION to show login errors to user. It was working with no problem. Few days ago, I have changed my host from a Plesk host to a cPanel host that runs safe_mod off. Somehow my $_SESSIONs at login page doesn’t work. I test $_SESSION on index page and it works OK and it show nothing wrong with working of $_SESSION function. Both page included same session starter page.
Also nothing works on login page when my functions file included. (sessions, post items, classes, functions etc. nothing.) But everything works on index page even if functions file included. What’s happening here? What can be the reason?
PS: I am using UserCake for members system. My server doesn’t allow me to turn PHP errors at htaccess level and nothing seems with
error_reporting(E_ALL);
ini_set('display_errors', '1');
Also nothing seems relevant at my error logs.
Edit: We succeeded to show errors using
ini_set('error_reporting', 8191);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
thanks to @J A but no errors seems.
3
Answers
Either one of the following solutions.
Put session_start(); on top of the pages you are accessing $_SESSION from.
Check your php.ini, you can set session autostart to 1 if you don’t want to follow the other solution.
I know this answer is silly…. But I think you have missed session_start(); on the top of your login page
Or what I guess is you must have used same page for login and logout. Therefore the session is being unset or destroyed due to misconfiguration. If it is so, check the code once or seperate the files for login and logout…
add session_start() right at the top of the file