1

having big trouble managing my sessions so I'm asking help.

the scenario

from 1 iphone I load index.php login form here

jquery

$("#login").live('click', function(event) {
   //here I've the user input username and password an load the login.php
}

in login.php I also have the session_start() and If user is indeed who he claims to be I declare session['user'] = $user; and session['pass'] = $pass; and then redirect him to imap.php

imap.php has also session_start()

he does everything and returns a html string with some divs I will use as buttons

jquery

$("#erase").live('click', function(event) {
    //here i load the erase.php

erase.php

also have session_start(), but now the session['user'] and session['pass'] are gone...

all the loads are made with post method

What can I do to maintain the sessions variables?

Thanks

Pluda
  • 1,479
  • 6
  • 21
  • 45
  • Did you check if a new session was created? A new session would look exactly the same as those those variables "Vanishing", since they were set in some other session. – Marc B Mar 26 '11 at 19:43
  • sorry, didn't untherstand your post, yes a new session is created... i read the php sessions documentation, but got no resul, maybe using session_name(test), and then calling in each php file for session_name(test).some_var, but don't know how to do this :-( Thanks for reply – Pluda Mar 26 '11 at 21:02
  • Check if the session id (retrieved with `session_id()` remains constant throughout all the requests. if it changes, most likely a new session is being generated each time. – Marc B Mar 27 '11 at 02:35
  • hello, session_id is always diferent... I do have all session_start just after , whats the intent of ssign a session_name ? don't know what to do – Pluda Mar 27 '11 at 17:43
  • session_name() is simply the name of the cookie that gets sent to the client, which will contain the session ID. since the ID is changing each time, something's causing your cookie to not "stick", and a new session is created each time. – Marc B Mar 27 '11 at 18:43

1 Answers1

0

One very important thing to remember is that session_start() must be called first, before anything in your php script.

example:

..the rest of your code

?>

Also, make sure there is no whitespace between the session_start() and the

It would also be a good idea to check your error log file (assuming you have one). They are very helpful when working with sessions.

Hope this helps!

Ben
  • 63
  • 1
  • 6
  • thanks for reply, i'm going to check that (tomorrow, not at office now), I know I've the serve as gzip comand before session_start, but its the only thing. – Pluda Mar 26 '11 at 21:30
  • hello, no white space after and all session_start() are in first line of each php... I'm using charles to see whats going on, but no great help in this, no error log file. thanks – Pluda Mar 27 '11 at 17:47