20

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?

Chenmunka
  • 685
  • 4
  • 21
  • 25
Okan Kocyigit
  • 13,203
  • 18
  • 70
  • 129

6 Answers6

44

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.

idmean
  • 14,540
  • 9
  • 54
  • 83
Mughil
  • 670
  • 8
  • 13
  • 1
    I tried both method, I have but session save path always return /tmp, It's not changing. – Okan Kocyigit Jan 19 '12 at 20:45
  • 2
    Note that "sessions.save_path" is incorrect as the commenter below notes--it should be "session.save_path". Once I removed the "s" and had session.save_path, it worked for me. – Nate Beaty Aug 11 '13 at 18:29
  • 2
    The correct syntax is `ini_set('session.save_path', '/path/to/your/folder')` – revoke May 13 '15 at 07:25
9

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

KANAYO AUGUSTIN UG
  • 2,078
  • 3
  • 17
  • 31
Iburidu
  • 450
  • 2
  • 5
  • 15
2

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

Rotimi
  • 4,783
  • 4
  • 18
  • 27
1

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

Chris Walsh
  • 3,423
  • 2
  • 42
  • 62
chart41
  • 11
  • 1
0

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.

kamaci
  • 72,915
  • 69
  • 228
  • 366
0

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();
...
Gregory Bologna
  • 270
  • 1
  • 6
  • 20