SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session_set_save_handler misunderstanding

    As some of you may have realised I am having one or two understanding issues with some of PHP at the moment. I have been reading a book and I am finding the custom session handler part confusing.

    I have copied code from the book which overrides the six functions that need to be overridden. I have passed these function names to the set_save_handler function which, as I understand it, sets them up as callbacks. My question is that I am not clear as to which methods to call to use them. I can work out that session_start() calls the open function I have declared but which of the session functions allow the rest to be used.

    I have searched the php function reference and can't find the info I am after. Can anyone give me a definite mapping for the functions mentioned please.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You don't need to call them PHP does that for you.

    Just use sessions normally e.g. $_SESSION['key'] = 'value';
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    You don't need to call them PHP does that for you.

    Just use sessions normally e.g. $_SESSION['key'] = 'value';
    Well thats partly whats confusing I added a new session variable like so:
    Code:
    $_SESSION['surname'] = "Glass";
    but it never made it to the database.

  4. #4
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A little more info. If I refresh the page, in the example above, the new session variable does not propogate to the database. If I delete the cookie and then refresh the page I get a new entry in the database with a different SID and the new session valriable is included. I can access the session variable on the page and use it but it does not seem to be passed to the database once the session has been initially created. What am I missing.

    [edit] ok scrub that it seems to be working as expected now. Not sure why but I just added a new variable and itr showed up immediately in the db. Thanks anyway.

  5. #5
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am at home now and I have the old behaviour happening. Any new session variables I declare do not make it to the db. At work I was using a Windows machine and it eventually worked. What I changed was the php.ini file. I had left this file as php.ini-reccommended (or whatever it is called) and changed the use only cookies to 1.

    I am now at home on my Linux desktop and it does not seem to be working here. I am following the same example as before and adding an extra session variable which is not visible in the database when I check after refreshing the page. Removing the cookie and then refreshing the page then gives a new session in the db with the data I expect to see. If I then add another session var and refresh the new one will not be in the db. This can't be correct behaviour and I would appreciate someone explaining what I am doing wrong to cause this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •