Skip to content Skip to sidebar Skip to footer

Want To Hide Cgi Rendered Html Text For Hostname When Username Text Column Is Empty

I have the current perl code in a .cgi file that we run on our server. This allows us to know which employees are using specific machines, by displaying: hostname - username Howeve

Solution 1:

It's not really clear how your database is laid out, but I think that if no-one is logged in on a host then the $currentuser variable will be undefined. So within the main loop that creates the table, you could just skip an iteration if that's the case. Something like this:

while($sth->fetch()) {
    nextunlessdefined $currentuser;

    # Rest of your existing code
}

But all in all, this code needs a lot of work. I'm sure it currently does what you want, but it's an unmaintainable mess which is very likely to fall apart if it's not cleaned up soon. Some suggestions:

  • Add use strict; and use warnings; and then fix all the problems they reveal.
  • Use Time::Piece instead of calling the external date command.
  • Put the hostnames in a database table and join against that table in your SQL.
  • Stop using bind_columns. It's more readable to do something like:

    while (my @row = $sth->fetchrow_array) {
       my (undef, $currentuser, $lastlogin, $host_name) = @row;
    
  • Use a templating system for your HTML output.

Post a Comment for "Want To Hide Cgi Rendered Html Text For Hostname When Username Text Column Is Empty"