Problems with session variables

Discussion in 'Integration' started by kenmarep, Feb 21, 2010.

  1. kenmarep

    kenmarep New Member

    Joined:
    Jun 27, 2008
    Messages:
    12
    I need to access the user's amember username so I can store info they provide in a mysql db and retrieve it whenever they want it.

    If the user has just logged in I can use the session variable method to access the amember username no problem.

    However, this doesn't work in cases where the site is accessible to the user via cookie (through a previous successful login).

    I know this is an issue with session variables, but I need a foolproof way to be able to get the username at all times regardless of how amember gives the person access (session vs cookie).

    I guess one way to enforce this is to only set the cookie expiration to the same duration as the session (how do I do this?)

    Perhaps others have another way to tie data to specific members?

    A big thanks in advance!
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    so you are using the $_SESSION['_amember_login'] and this is not working for you?

    One option is to create a simple plugin that generates your own cookie that should be a bit less sensitive (with the exception of the user clearing their cookies that is :-p)
  3. kenmarep

    kenmarep New Member

    Joined:
    Jun 27, 2008
    Messages:
    12

    Here's an example of the problem:

    I login and all session variables are available and work (yes, using $_SESSION['_amember_login']).

    I then ignore the site for say, 2 hours. I leave the tab open but spend the time away from the computer or surfing other sites in different browser tabs.

    When I refresh the site tab, I'm still logged in but the session variables are empty.

    Writing my own cookie seems like an imposing job - I'd have to intercept every login, logout, timeout etc. I 'm not sure I can do that.


    By the way, it's probably relevant to say I'm using new_rewrite to protect the folder.
  4. erwinvdb

    erwinvdb aMember Pro Customer

    Joined:
    Aug 30, 2007
    Messages:
    264
    Seems like you're developing your own plugin. May I suggest to check out that part of the manual. Maybe you get some creative ideas from that to fix it?
  5. kenmarep

    kenmarep New Member

    Joined:
    Jun 27, 2008
    Messages:
    12
    I'm not writing a plugin. I simply have php page that stores and retrieves a single record from a database based on the member's login credentials.

    My site is fully working and ready to go live except for this problem which came up in final testing. This is a dealbreaker. I need to be able to save info based on a unique member id.

    I don't want to add code or complicate the site unnecessarily when it shouldn't be needed. My strong preference is for the amember software to work as advertised.

    I have found amember session variables in conjunction with new_rewrite to be completely unreliable. Specifically, the session variables disappear while the user remains logged in.

    The script I'm using to test is:

    PHP:
    <?php 
    session_start
    (); 
    ?><pre><?php
    print_r
    ($_SESSION); 
    ?> 
    It lives in the member's protected area.

    I don't want to complicate my site and lose dev days by coding around the problem. I'd rather resolve it.

    Thanks for the responses so far. Any ideas how I can *fix* this?
  6. kenmarep

    kenmarep New Member

    Joined:
    Jun 27, 2008
    Messages:
    12
    So we can go ahead with our launch, I'm going to go with the simplest workaround I can for this problem.

    At the start of each php page I will check to see if the session variables are still available. If not, I will force logout the member. When they log back in the session variables will be set correctly.
  7. erwinvdb

    erwinvdb aMember Pro Customer

    Joined:
    Aug 30, 2007
    Messages:
    264
    Maybe it wasn't your first intention to develop a plugin, but what you wrote points in the direction that you are, perhaps not consciously ;)
    Just check the manual part that describes the plugin development. If it's of no use than no harm would be done anyway, now would it?
  8. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Ken,
    I believe the problem is php sessions Garbage Collection.
    Try to tune session.gc_maxlifetime setting in php.ini

Share This Page