John
John

Reputation: 4944

PHP session cookie seems to gone when URL does not have WWW in front of it

I put this on my index file:

session_set_cookie_params(31536000);
session_start(); 

It keeps users logged in even when the browser is closed and re-opened.

However, it only works when a WWW in front of my URL. Is there a way to make it work without the WWW in front of the URL?

Upvotes: 2

Views: 128

Answers (1)

Decent Dabbler
Decent Dabbler

Reputation: 22783

As per the docs, use this:

session_set_cookie_params( 31536000, '/', '.example.com' );

This will allow the session cookie to be valid for every path (second argument) and every subdomain of example.com (third argument). Replace .example.com with your own of course.

Upvotes: 4

Related Questions