Nik has asked for the wisdom of the Perl Monks concerning the following question:
Is there any other better way to write the above code? I want the logs database to add +1 to variable visits each time the same user visits my webpage again!%cookie = fetch CGI::Cookie if $ENV{HTTP_COOKIE}; $cookie1 = cookie( -name=>"host", -value=>$host, -expir +es=>"+7d" ); $cookie2 = cookie( -name=>"xronos", -value=>$xronos, -expir +es=>"+7d" ); $cookie3 = cookie( -name=>"visits", -value=>cookie(visits) + 1, -expir +es=>"+7d" ); print header( -charset=>'iso-8859-7', -cookie=>[$cookie1, $cookie2, $c +ookie3] ); ............................... ............................... ............................... if ( $ENV{HTTP_COOKIE} ) { $st = $db->prepare( 'SELECT * FROM logs' ); $st->execute(); while ( $row = $st->fetchrow_hashref ) { if ( cookie(host) eq $row->{host} ) { $db->do( "UPDATE logs SET visits = visits + 1" ) or die $db-> +errstr; } } } elsif ( !$ENV{HTTP_COOKIE} ) { $db->do( "INSERT INTO logs VALUES ('$host', '$xronos', 'index', 1)" + ) or die $db->errstr; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cookies or maybe another way to do it.....
by tachyon (Chancellor) on Jun 27, 2004 at 23:27 UTC | |
|
Re: Cookies or maybe another way to do it.....
by borisz (Canon) on Jun 27, 2004 at 22:55 UTC |