php - Session not saving for whole site -
I have a very strange problem with php session functions.
First of all: Works in browsers random Select: FF on windows, but not on Mac, Chrome on both platforms, Safari IE does not work.
I have a login script, where I will create a session if the login data is correct:
session_start (); $ _SESSION ['username'] = $ user_info ['username']; Echo "& lt; east & gt;"; Print_r ($ _ session); Echo "& lt; / pre & gt;"; When I print_R in the login script, after setting the session variable, it works for all browsers. But after redirecting the user to the main site, the session is empty for some browsers ....
I never had such a problem and I really do not know what to do ... < / P>
session_start (); $ _SESSION ['username'] = $ user_info ['username']; Echo "& lt; east & gt;"; Print_r ($ _ session); Echo "& lt; / pre & gt;"; If it is that every page starts, I can understand that after refreshing do not see anything else anymore, just because of what you do, you start your session You do, you set the $ _SESSION variable user name on variable $ username_info and you do this every time.
But consider: Your variable is not exactly specified at this point. It may be that you set it to when you log in, however, you clean it on the next refresh, because you can tell that $ user_info ['username'] will be used again. In this case, nothing is said to be said, it will be an empty variable, thus your username will be empty.
Your session ['username'] will also be empty, Say for taking information.
When you are logged in, since you set it up, there is no need to denote that, your session [user name] is already set up
Edit
So I ask now, what do you put in your database? Do you save session IDs in your DB? So you can do something like that.
session_start (); $ Session = session_id (); $ Result1 = LoadSession Data ($ Session); $ = Mysqli_num_rows ($ result1) count; If ($ count == "0") {$ time = time (); $ Ip = $ _SERVER ['REMOTE_ADDR']; StartSessionData ($ session, $ time, $ IP); $ _SESSION ['username'] = ''; } And {while ($ row1 = mysqli_fetch_array ($ result1)) {$ user name = $ line1 ['gebrucker name']; If ($ user name == "") {$ _SESSION ['username'] = ''; } $ Time = time (); $ Time_check = $ time 3600; $ Ip = $ _SERVER ['REMOTE_ADDR']; OnlineChecker ($ session, $ user name, $ time, $ IP); }} I hope you can follow it, but I will try to explain. It checks whether the session ID is in the database, if not, add session IDs to the database with timestamp, IP and session username, which is set to empty.
Otherwise, I'll check what I'll come back if its username is used, if it is empty, then the name of the session will be empty, because later checked with that username. If I'm logged in. Then I update the database with username, time, etc.
Comments
Post a Comment