Harfish
11-06-2006, 06:13 PM
I've got a login script I've written that works absolutely fine but I want to add another feature to it. Currently it logs the user name, computer name and time that a user logs in. I'd like to add IP address as well. What's the cleanest way of doing it?
Here's my code I'm using for the rest of my script
my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password");
$user = Win32::LoginName();
$name = Win32::NodeName();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$timedate = sprintf "%4d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec;
$sqlstatement = "INSERT INTO users (client, user, timedate) VALUES ('$name','$user','$timedate')";
$sth = $dbh->prepare($sqlstatement);
$sth -> execute || die "Could not execute SQL statement";
$sth->finish();
$dbh->disconnect;
Here's my code I'm using for the rest of my script
my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password");
$user = Win32::LoginName();
$name = Win32::NodeName();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$timedate = sprintf "%4d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec;
$sqlstatement = "INSERT INTO users (client, user, timedate) VALUES ('$name','$user','$timedate')";
$sth = $dbh->prepare($sqlstatement);
$sth -> execute || die "Could not execute SQL statement";
$sth->finish();
$dbh->disconnect;