Forum Moderators: coopster

Message Too Old, No Replies

Session variables in remote file not created

         

mealybar

10:41 pm on Jan 3, 2006 (gmt 0)

10+ Year Member



Hya :)
I'm rewriting my login script to improve the security >alot< and make it easier to update. I have my login.php, and a seperate file of functions.

Everything works but when I try to set a new session variable in the remote file (functions file).

The functions file is linked to the login.php via require(); and is not .php extention (parse errors fix). My code to set a new session variable works in the login.php (but not in remote file - problem), and is:

$_SESSION['var1'] = "textstring";
$_SESSION['var2'] = $textvar;

^^in functions file

The only difference in my login.php file the session variable is set: $_SESSION['var3'] = funct1(); <<which returns a string.

Thanks in advance :)

FalseDawn

6:48 am on Jan 4, 2006 (gmt 0)

10+ Year Member



Make sure the session has been started before the "require" statement.

mealybar

6:08 pm on Jan 4, 2006 (gmt 0)

10+ Year Member



The session is started on the first line of the login file. Then the functions file is required, then I put a security string on the session (works) and then call the 'isalreadyloggedin' function (true if already logged in -> redirect to other page). If the user is not already logged in it outputs a html form to login. Submit and the page reloads with q string mode=login, which sends the form data to the login function to process the login. There is a bit of form data validation, if correct then the user is logged in in the following way;
- the session id is regenerated
- try and set my 2 session vars (not working)
- set a security cookie
- then send the loggedin output to the page which redirects to the menu page

I'll try setting the session vars before the session regeneration :)

mealybar

2:52 am on Jan 5, 2006 (gmt 0)

10+ Year Member



No luck, even with the session regenerate off it still does not work. I've tried commenting bits out and 'exit;' the script at the point to see if these variables are created, which they came out to be :S

Here is my code (not working):

<<Before: the login function, testing for valid username, password, etc so this bit is the last of a list of else statements: $user and $pass are passed into the function>>

//Value for cookie
$kval = md5(md5($pass));

//Set a validation Cookie
setcookie("name",$kval, time() + 86400,"/folder",".domain.com",0);

//Regenerate the Session ID
//OFF session_regenerate_id();

//Issue the Session with a Loggedin/username var
$_SESSION['loggedin'] = "yes";
$_SESSION['user'] = $user;

<<AFTER goes on to log the login to a log file, set some variables for the output and calls the html output function, then exit;>>

This is in the remote file^^