PHP: session_set_save_handler: first parameter: what to set the save path to?

Posted on 2011-10-12
Last Modified: 2012-05-12
Hello Experts,

the session_set_save_handler has 6 parameters. the first one, Open, expects two parameters, where the first is the save path and the second is the session name.

What do most programmers set this save_path to?
In other words, what do I set this to?

Question by:epifanio67
    LVL 13

    Expert Comment

    Isn't that parameter sent to your function from php?
    LVL 13

    Accepted Solution

    You are trying to make your own custom session handler, correct? You aren't simply just trying to use sessions, you want to invent your own wheel?

    if so, in other words, you simply set up your custom session like this:
    function open($path, $name) {
      global $session_path;
      $session_path = $path;
    session_set_save_handler("open", "close", "read", "write", "destroy", "gc");

    Open in new window

    When your "open" function is called, php will send you the save path. That save path is set in php config and doesn't need to be messed with

    Author Comment

    thank you experts...


    on your example above, the method Open, I still don't see what $path is set to?

    do I have to specify a directory on the server? example

    $path = '/sessions';

    or is there a default?

    see what I mean?

    thanks so much for your help..
    LVL 3

    Expert Comment

    Depending on the type of server you're running it can vary. To locate the directory, search for the following in your php.ini file.

    upload_tmp_dir = "/tmp"

    The directory can be different for you.

    Author Comment

    thank you expert,

    but I don't have to set $path to any directory... the variable $path is set at the php.ini file, correct?

    sorry, I just want to make sure I understand...

    thanks again...  


    Author Closing Comment

    I got it... thank you experts..

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now