Not directly related to the code:
Your table should have a UNIQUE constraint on the host field. This will avoid some precious time cleaning the table if something goes wrong, wich was the case here.
Directly related to the code:
if ( $ENV{HTTP_COOKIE} ) {
#
# Some code here
#
}
elsif ( !$ENV{HTTP_COOKIE} ) {
#
# Some code here
#
}
Your
elsif is rubbish, since your testing only one condition. It should be replaced by a simple
else.
Regards,