0

I have a CodeIgniter website running in a subdomain.

The session values don't pass between one page and the other. For example, if I put $_SESSION['ouch'] = "Bla" on one controller method that handles a page, the value is gone when the page redirects to another page. That behavior makes login in impossible.

These are my CodeIgniter config settings when it comes to cookies and sessions. I have tried variations, but the session values disappear as soon as the login page redirects.

$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = false;
$config['cookie_httponly'] = false;
Roddy P. Carbonell
  • 858
  • 1
  • 11
  • 16
  • As long as you are staying within that subdomain, I don't think that fact is actually relevant here (even the standard `www.` prefix, is technically a "subdomain".) What does the actual Set-Cookie header look like, when you inspect a request using your browser dev tools? – CBroe Aug 25 '22 at 10:41
  • Which CI version are you using? Which PhP version? – Vickel Aug 25 '22 at 12:13
  • It is CodeIgniter 3.1.11, and PHP version 7.4.3 – Roddy P. Carbonell Aug 26 '22 at 04:56
  • have a look here, the session patch helped me to fix a CI 2.x app, which I couldn't update. There are also some answers issued to CI 3.x: https://stackoverflow.com/questions/14472869/codeigniter-session-data-lost-after-redirect – Vickel Aug 27 '22 at 17:05

1 Answers1

0

If I add the following to the index.php file:

session_start();

The problem goes away. But I am not sure if this is the proper solution to the problem.

Roddy P. Carbonell
  • 858
  • 1
  • 11
  • 16