LeonLatex Posted December 12, 2025 Share Posted December 12, 2025 (edited) I have a problem with session start. It messes up my site a bit too ******. This is a hybrid CMS/SPA site that fetches pages via slugs. Pages fetched via slugs fetch their content and data from the database. The problem is: Check if session is already active before starting. if (session_status() === PHP_SESSION_NONE) { session_start(); } Index.php is the page that opens everything, page_home.php is one of the files that is included in the CMS. page_home.php is the main file, and the file in the CMS that opens and navigates the CMS/SPA I thought that as long as I had: if (session_status() === PHP_SESSION_NONE) { session_start(); } ... Then I could have session_start on multiple pages, but it crashes and breaks my site. It looks like a mess. The reason I want the session_start control is because it seems like a single session_start is not able to keep the session going throughout the website. Can anyone tell me if they have encountered this before, and tell me what I am doing wrong? I am almost out of hair as I am scratching my head so much about this problem! Edited December 12, 2025 by LeonLatex Quote Link to comment https://forums.phpfreaks.com/topic/332407-session_start-problem/ Share on other sites More sharing options...
mac_gyver Posted December 12, 2025 Share Posted December 12, 2025 When the web page is messed up, what does the 'view source' in the browser show? Quote Link to comment https://forums.phpfreaks.com/topic/332407-session_start-problem/#findComment-1661975 Share on other sites More sharing options...
maxxd Posted December 12, 2025 Share Posted December 12, 2025 It's been a while since I've dealt with sessions manually (been in Laravel land for the last 7 or so years), but according to the docs: Quote session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. As far as I can remember as long as you're piping everything through your front loader, a call to session_start() in that file should be sufficient. If you're using index.php as the front loader on some routes and page.php on others, try adding the session_start() call to page.php? Quote Link to comment https://forums.phpfreaks.com/topic/332407-session_start-problem/#findComment-1661977 Share on other sites More sharing options...
gizmola Posted December 14, 2025 Share Posted December 14, 2025 You should not be trying to programmatically determine whether to call session_start. You should simply be calling it at the start of your index.php file. if it "loads" everything else, there is no need to have session_start calls anywhere but the index.php. The session will already be available to any of the include/required scripts. Remember that $_SERVER is a superglobal, and is always available globally. 1 Quote Link to comment https://forums.phpfreaks.com/topic/332407-session_start-problem/#findComment-1661986 Share on other sites More sharing options...
Strider64 Posted December 21, 2025 Share Posted December 21, 2025 It's kind of redundant checking if session_start has been executed as if you are checking to see if it has been started it's 99.9 percent too late. Quote Link to comment https://forums.phpfreaks.com/topic/332407-session_start-problem/#findComment-1662048 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.