Username variable in menu

Hi Guys,

I have 2 applications

One called frmLogin and one called frmMenu

The login is the first login form with 2 fields for username and password, i have an onvalidate event as follows.

sc_lookup(dataset, "SELECT count(*)
 FROM TblUsers
 WHERE 
 Username = '{Username}' and 
 Password = '{Password}'");
$vuser = {Username};
if({dataset[0][0]}<=0)
{
sc_error_message("Invalid Username or Password.");
}

I would like to pass the username as a variable so i can use it in the menu header (You are logged in as: [username]

How is this done please?

Is it also possible to set access rights on certain fields, blocks, tabs, buttons etc so I can allow access from my tblusers so that each user has access to different levels??

Thanks

Craig

Re: Username variable in menu

sc_lookup(dataset, “SELECT count(*)
FROM TblUsers
WHERE
Username = ‘{Username}’ and
Password = ‘{Password}’”);
$vuser = {Username};
if({dataset[0][0]}<=0)
{
sc_error_message(“Invalid Username or Password.”);
} else {
$_SESSION[‘global_user_name’] = {username}; // or $vuser as you have listed above
$_SESSION[‘global_user_level’] = {my_level_field};
}

As for the levels, just use the code above and then use options like:

sc_field_display()
sc_block_display()
sc_button_*()

Regards,
Scott.

Re: Username variable in menu

Hi zeroms, What Scott tells you to do is to create a session variable with the username, or id, or whatever you want to do.

As you can see in the OnValidate event, if dataset is != ‘0’ you create those variables, and they will be spread over all your system.

In the menu app, you can put that info wherever you want (layout settings, by example) by entering [yours_session_name] or $_SESSION{‘yours_session_name’]

Re: Username variable in menu

when does this session expire?

Re: Username variable in menu

When you end it.

-Exit the app
-Timeout is reached
-Call functions that end session

Regards,
Scott.

Re: Username variable in menu

How can this time-out be set? thanks.

Re: Username variable in menu

The main location is the PHP.ini
You can also setup overrides in your code (in each app)
I believe V5 also has a option in settings for this.

Regards,
Scott.

Re: Username variable in menu

<?php
ini_set(“session.gc_maxlifetime”, “18000”);
?>

<?php
echo ini_get(“session.gc_maxlifetime”);
?>