Gossamer Forum
Home : Products : DBMan : Installation :

Global Variables

Quote Reply
Global Variables
Hello Dbman addicts :-),

How do I make a variable global without using the .cfg file?

This is what I am trying to do...

I have dbman set up so that when the user creates its own account it will also ask for other information such as e-mail, telephone, Full name, etc... This information is stored in the password file along with the permissions and password.

What I am trying to do is to get all that information when the user logs in and put it in global variables so I can use them throughout the script without having to query the password file over and over again (this is what I currently have).

Thanks
Cheers
-JO
Quote Reply
Re: Global Variables In reply to
Hi Jamie,

By default, variables are global. If you don't declare them with my() or local() they will stay around until the program dies.

It's generally not a good idea to keep something global when it doesn't need to be. However, in your case, read the password file once and store the extra info in the variables you want, just make sure you don't declare them with my().

Hope that helps,

Alex
Quote Reply
Re: Global Variables In reply to
Hi Alex,

Well, that is what I thought but I seem to be loosing them somewhere...

Here is what I have:

In html_home sub
($Name_of_User,$Telephone,$View_Secondary)=&get_user_info;

In html_record_form

Code:
$rec{'Telephone'}=$Telephone;

<TD ALIGN="Right" VALIGN="Center"><$font><b> Telephone:</b></FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Telephone" VALUE="$rec{'Telephone'}" SIZE="16" MAXLENGTH="20"></TD>

And the get_user_info sub is the following
Code:
sub get_user_info {
# --------------------------------------------------------
# Returns the name of the logged user, his/her the phone number and Secondary View option
#
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

foreach $line (@lines) {
if ($line =~ /^$db_userid/) {
$Name_of_User = (split (/:/, $line))[9];
$Telephone_of_User = (split (/:/, $line))[10];
$View_Secondary = (split (/:/, $line))[11];
}
}
return ($Name_of_User,$Telephone_of_User,$View_Secondary);
}


The Telephone of the user does not show in the table unless I call &get_user_info inside the html_record_form sub.

What am I missing...?

Cheers
-JO


[This message has been edited by Jaime Ortega (edited March 22, 1999).]