How to enable PHP Sessions in Wordpress?

Asked

Viewed 446 times

4

I am developing my site using the Wordpress platform.

I really, really needed to enable PHP Sessions within the platform, for logged users to stay logged in within the subdomains I’m creating.

Any suggestions? I’ve tried to enable this by a plugin but it didn’t work. It gave error messages in the header.

Observing: The wordpress version I’m using is 4.3

  • Man, I did a thing like that a while ago. As soon as I remember how I did it I send you here

  • Also try: http://wordpress.stackexchange.com/

  • Wouldn’t your best exit be the implementation of a SSO (Single-Sign-On)? There are several available in the repository: https://wordpress.org/plugins/tags/single-sign-on. In particular, I tested the Auth0 with c# and it was very simple.

1 answer

2

Hello try to make one of the options:

In generic PHP you use so:

ini_set('session.cookie_domain', '.domain.tld');
if ( empty(session_id()) ) session_start();

No . htaccess:

php_value session.cookie_domain .example.com

In Wordpress wp-config.php:

define('COOKIE_DOMAIN', '.domain.tld');

This session can only be shared in a single Wordpress installation. I mean, if you have other subdomains with another Wordpress installation, this setting might not work, since Wordpress has another session for another installation.

Maybe it’ll help :)

  • 2

    Great thinking. Congratulations!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.