irishwill200 irishwill200 - 11 months ago 61
PHP Question

Setting session_set_save_handler for one page only

In my php.ini i have the following set:

session.save_handler = redis
session.save_path = "tcp://localhost:6379?weight=1"

But i want to keep that set as it works with this system im using but only thing is when i try create session it gives me errors.. Going off point.

Issue is, im trying to set the save handler then as files ONLY for my login.php and then after that use redis.

I have the following code in my file but doesnt change from redis to files:

session_start(); // Starting Session

Answer Source

The session_set_save_handler function doesn't exactly do the same thing as the session.set_handler configuration directive. The former expects a callable type as its first argument, whereas the latter expects a scalar value as one of the registered handlers in PHP.

What you want is to say ini_set('session.save_handler', 'files').

When you set the session.save_path for the redis session handler, you should avoid using hostnames that can't be resolved directly through your DNS resolver. That's pretty much anything that you put in /etc/hosts like localhost. Instead, try using the IP address that redis is listening on directly, such as The reason for this is that PHP won't attempt to look at /etc/hosts directly when resolving the hostname.