Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a login-form located at ?action=panel that is showing an 'interesting' behaviour:

I use a function called performLogin to check against DB, most code I left out for readability.

function performLogin()
{
// check for valid login and such
  if ( valid )  // fake metacode
  {
    $_SESSION['user_id'] = $user_id;
    header("Location: ?action=panel" );
    exit();
  }
}

If I call this function directly, it will check, update session and redirect just fine WITH a working session.

Now sometimes I must convert users from an old format which works with:

function convert()
{
// do some DB stuff
  if ( converted )  // fake metacode
  {
     performLogin();
  }
}

This is when stuff breaks. I can insert a breakpoint before the redirect and the _SESSION will be as it should be, after allowing the redirect it will be gone. Remember, calling performLogin directly always works.

One of the first things executed in index.php:

session_name("project_session");
session_start();

But it's getting even better:

Changing the redirect to anything different than "?action=panel" (with or without the domain in front) will work just fine. Also, if I comment the redirect out and manually go to ?action=panel, it works.

Things I tried so far:

-redirect with and without domain/URL before redirect: (one ore more of them)

-sleep(2);

-session_write_close();

-session_regenerate_id(true);

share|improve this question
 
Can we please see the code leading up to the function calls in question. It's hard to know what's going on if we can't see the functions in context and what's going on around them. –  adear11 Jun 8 at 23:52
1  
Is your browser dropping the cookie? Check your browser to make sure it still has the cookie with your session id. –  chrislondon Jun 9 at 4:39
 
@adear11: Both functions sit inside a class: performLogin() is called directly if the _REQUEST sends login data. convert() is called from a simple form if the user-data is stored in an old format. I am having a hard time pulling the functions out of their context without posting half the userpanel in this place. Does this help? –  websheep Jun 15 at 13:53
 
@chrislondon: Cookie is there –  websheep Jun 15 at 13:54
 
Can you post the code in pastebin and link here? Most likely the session is being reset or not properly started after the redirect, but there isn't enough code here for us to be able to figure out what might be going on. –  adear11 Jun 16 at 15:38
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.