This topic is locked

Session variables

8/21/2006 4:35:06 PM
PHPRunner General questions
A
andyjames author

Hi
Getting my knickers in a twist here. After referring to other posts on session variables, I have set the following code as a Global Event in AfterSuccessfulLogin:

function AfterSuccessfulLogin()

{

//********** Custom code ************

// put your custom code here

global $conn;

$strSQL = "select name, lingregister_date, lingupdate_date, mothertongue from ling_linguists";

$rs = db_query($strSQL,$conn);

$data=db_fetch_array($rs);

$_SESSION["var_name"]= $data["name"];

$_SESSION["var_regdate"]= $data["lingregister_date"];

$_SESSION["var_updatedate"]= $data["lingupdate_date"];

$_SESSION["var_mothertongue"]= $data["mothertongue"];
//********** Redirect to another page ************

header("Location: menu.php");

exit();

}


I want to be able to set these variables as session variables for use in other tables BUT SPECIFICALLY FOR THE USER THAT LOGS IN. For some reason it always returns the Administrator, which is the first person in the table. I can't access the session variables in php on the remote server as it is hosted. I have tried to unset them but to no avail.
Please can you advise. Thanks.

J
Jane 8/22/2006

Andy,
this issue occurs because you select all user data from table.

Try to use following code:

function AfterSuccessfulLogin()

{

//** Custom code ****

// put your custom code here

global $conn;

$strSQL = "select name, lingregister_date, lingupdate_date, mothertongue from ling_linguists where FieldName='".$_SESSION["UserID"]."'";

$rs = db_query($strSQL,$conn);

$data=db_fetch_array($rs);

$_SESSION["var_name"]= $data["name"];

$_SESSION["var_regdate"]= $data["lingregister_date"];

$_SESSION["var_updatedate"]= $data["lingupdate_date"];

$_SESSION["var_mothertongue"]= $data["mothertongue"];
//** Redirect to another page ****

header("Location: menu.php");

exit();

}



where FieldName is you actual field name in which login name is stored.

A
andyjames author 8/22/2006

Hi Jane,
A thousand thanks. That worked perfectly. Great support.