0

I have a config.php which basically just has session_start();

I include it in my header.php via

include_once("config/config.php");

This works great on localhost, but the session doesn't start on my live WebHost. If I add session_start(); To the top of each page(above the include_once('includes/header.php);, it then works on my live website.

All of the HTML/CSS/js from the Header.php loads just fine, but the session doesn't seem to start for some reason. Works on local, not on production. Any suggestions?

I hope this makes sense, Thanks.

Xab Ion
  • 1,105
  • 1
  • 11
  • 20
Zach
  • 1
  • 2
  • 1
    I would recommend checking if the word-case is correct between the filenames and your include_once statements. Different operation systems might handle this differently. – thephper Sep 23 '22 at 15:09
  • Also check your web servers error log if you have any errors/warnings/notices. – M. Eriksson Sep 23 '22 at 15:11
  • It also matters which working directory is set for your production server's PHP execution environment. Relative paths work in relation to that, and are not relative to the PHP file with the include statement itself. You might want to construct absolute file paths instead. See also https://stackoverflow.com/questions/17407664/php-include-relative-path – tiguchi Sep 23 '22 at 15:12
  • @thephper I have adjusted the config and added ```echo "Config page loaded";``` I have found that this text outputs, but the session_start(); for some reason does not work. Config file: ```session_start(); echo "Config page loaded";``` Echos but I still need to add session_start() on all of the pages that I need to use sessions, regardless if ```session_start()``` is in config.php. You'd think this would throw errors/warnings because session_start() has already been called. – Zach Sep 23 '22 at 16:07

0 Answers0