How to change session_save_path in php.ini file?

2020-08-09 09:54发布

问题:

I have a shared hosting on godaddy.

I tried to change session save path in php.ini file with this line,

sessions.save_path = "/session"

I've controlled the sessions save path with sessions.save_path() function. It returns /tmp before and after changing php.ini

Is it possible to change session save path on shared hosting?
Where am I wrong?

回答1:

You can modify the session save path on shared hosting by creating a custom php.ini.

Include this in your file: session.save_path = "/path/to/your/folder"

Otherwise, you can use:

ini_set('session.save_path', '/path/to/your/folder')

The folder you use should be under your domain/account but not accessible through a Web browser. It also needs to have world-writable permissions on it. And every page that uses sessions must include that line.



回答2:

It is session.save_path and not sessions.save_path (it may have been renamed or something, I don't know, but sessions.save_path did not work for me)

session.save_path = "/path/to/your/folder" 

works fine



回答3:

It is also important to note that session.save_path must be called before session_start()



回答4:

Create a folder named session in the C:\session.

Change the session.save_path(); directory to the newly created path: (C:\session) anywhere out of tmp folder.



回答5:

Here's how I got sessions working, with help from this thread. I'm running PHP in IIS.

Set the session folder in php.ini.

session.save_path = "C:/inetpub/temp/php_session"

(I'm not yet sure if this session folder is best practice for my environment..security-wise. I need to do more reading on this.)

Setting the session path was not enough. At first, I had placed session_start() in a function where I needed to set my session variables but even though the session file was created in my path (sess_d9eeeb305928f2f39a25f296773b09eb), the $_SESSION value was lost during an ajax post to my PHP page. Someone on stack\o said to put session_start() as the first line, so I tried that and my session value is working. I haven't figured out where to destroy it.

<?php 
session_start();
...


回答6:

Check other files, for example: php_value[session.save_path] in /etc/php-fpm.d/www.conf and webservers users should have rights..