Back to Top

How to use Session Save Path in PHP

PHP supports session_save_path() function from version 4

What is session_save_path?

session_save_path() sets or returns the path where data for the current session is saved.If you pass no arguments into a function, it returns the current directory where session files are stored.

To Get default Session Path

By default, PHP stores session data in files and files are stored in the /tmp directory of your server.Each session is stored in its own file.

session data file stored in /tmp is like sess_1f1b1bdb809709f09f45b049998f25dc43745a67.

To Set Session Save Path in php.ini

session_save_path function returns the current session save path.If session_save_path() function returns null,then session.save_path is commented in your php.ini file.

So Uncomment session.save_path in a php.ini and set path in it.Let’s have a look

To Change Session Save Path

To change the default path of stored session, you can use same function session_save_path( ) but with the parameter which is the path of the new directory where you session files will be stored but you need to call this function before accessing any session variables like session_start();

NOTE:If sessions are not working or are giving errors, check the pathname returned by session_save_path() function and make sure that path exists and writable.

BENEFIT

This simple change can greatly improve the security of the sessions stored in files because we are storing it in custom directory for application so it is Securing Session Storage

Couple of articles, you may like:

Session In Magento
How to use Session in Joomla
To maintain session in WordPress

I hope you have enjoyed this article. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Share:
Share on Facebook0Share on LinkedIn0Tweet about this on TwitterShare on Google+0Buffer this pageDigg thisShare on Reddit0

Comments (3)

  1. You completed certain nice points there. I did a search on the matter and found nearly all persons will agree with your blog.

  2. I enjoy you because of every one of your work on this blog. My aunt really likes going through investigation and it’s really easy to understand why. Most of us learn all relating to the lively mode you deliver very important suggestions on the blog and therefore strongly encourage contribution from other individuals on the topic plus our daughter has always been being taught so much. Enjoy the remaining portion of the new year. You are always performing a dazzling job.

  3. this is quite similar to how sessions behave in Java applications

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular Posts

How To Turn On Output Buffering

Posted on 5 years ago

Bhumi

Control Flow Functions in MySQL

Posted on 2 years ago

Bhumi

How to Paginate WordPress Taxonomy?

Posted on 4 years ago

Bhumi

Facade implementation in Laravel

Updated 3 weeks ago

Bhumi

MySQL coalesce() function

Updated 17 years ago

Bhumi

How to use JavaScript Promise API?

Updated 17 years ago

Bhumi

What are Lambdas and Closures in PHP?

Updated 17 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi