php5 session woes

Discussion in 'PHP' started by caffeinefree, Sep 30, 2008.

  1. #1
    I recently ugraded to php5 for one of my clients and my sessions no longer work properly. The code base has worked perfectly under php4 for years. The problem is definitely related to cookies (won't set). I have troubleshooted this problem extensively and still cannot get a cookie set properly.:mad: I threw together a simple session script and it works fine. :confused: However, my more complex session code does not. :( I've tried ini changes and code changes to no avail. Anyone aware of session /cookie handling changes made to php5? Any new gotchas?

    Grant
     
    caffeinefree, Sep 30, 2008 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    Perhaps post sample code so we can all help.
     
    Kaizoku, Oct 1, 2008 IP
  3. caffeinefree

    caffeinefree Guest

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This section is called near top of index.php before any output. Nothing complex, just
    standard session starting. I also tried specifying domain and cookie path parameters,
    but it didn't help. I also ensure session auto start is OFF in php.ini

    $expireTime = 60*60*24; // 1 day
    session_name("supertime");
    session_set_cookie_params($expireTime); //set expiration time
    session_start();
     
    caffeinefree, Oct 1, 2008 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    Is there anything different between your V4 php.ini and your V5 php.ini ?
     
    joebert, Oct 1, 2008 IP
  5. caffeinefree

    caffeinefree Guest

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I did verify the critical settings were identical, but didn't compare everything. I will run a more thorough comparison and report back.
     
    caffeinefree, Oct 1, 2008 IP
  6. dwayne12

    dwayne12 Well-Known Member

    Messages:
    184
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Try re-ordering your code like this:

    
    $expireTime = 60*60*24; // 1 day
    session_set_cookie_params($expireTime); //set expiration time
    session_start();
    session_name("supertime");
    
    PHP:
    I haven't encountered such an error before, maybe its the order (doubtful, but worth a try), or it is your PHP settings. Maybe check your PHP.ini settings. If not, check you have permission to modify php.ini.

    I believe you should be looking under sessions in php.ini to see if session cookies have been enabled. From memory it's something like sessions.cookies.enable = 1 that it should be. Not sure if that's the right name, it's similar though.
     
    dwayne12, Oct 1, 2008 IP
  7. caffeinefree

    caffeinefree Guest

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I will give the reorder a try. I did verify the ini setting you mentioned. Appreciate the input fellas.
     
    caffeinefree, Oct 1, 2008 IP
  8. dwayne12

    dwayne12 Well-Known Member

    Messages:
    184
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #8
    No problem. If that doesn't work, post back and we'll sort it out.
     
    dwayne12, Oct 1, 2008 IP
  9. caffeinefree

    caffeinefree Guest

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Turns out I had an carriage return above opening php tag in one of my include files.:eek: Funny how we always overlook the simple stuff. Thanks again for the suggestions.
     
    caffeinefree, Oct 6, 2008 IP