How to change session_save_path in php.ini file?

a 夏天 提交于 2019-12-06 17:21:23

问题


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();
...


来源:https://stackoverflow.com/questions/8927404/how-to-change-session-save-path-in-php-ini-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!