Nik has asked for the wisdom of the Perl Monks concerning the following question:

while ( $row = $st->fetchrow_hashref ) { if ( $host eq $row->{host} ) { exit 0; } }
Hello, with the above code i try not to log again the same visitor that refreshes my webpage. I just want to log him only the first time thet he enters my page. if he hits the submit button and index.pl runs again or he just refreshes his browser i do not want my code to log him again. so i used the above code.

But the problem as i have it now is that the current hostanme is checking against the whole mysal table trying to find the exact match, when i only want the current hostname trying to match the last record entered i the mysql table. Or perhaps you have some better idea to log the user once but not continiously if he reloads the index.pl. But if the user checks my page at another time then i want him to be logged again. I do not want to use session variables for that. Thank you.

Replies are listed 'Best First'.
Re: logging the user once every session
by exussum0 (Vicar) on May 25, 2004 at 03:42 UTC
    It doesn't happen too often, but what about load balanced proxying? My company produces an application taht can't deal with that sorta thing. Neither will yours in this case if you do that.

    On load balanced proxies, it's typical for the least heavily loaded proxy to deal with your request. At some point, AOL did this. I advise you not do this and just use cookies instead. If you are really worried about security, a dedicated connection via a desktop application, instead of connectionless http, might be prefered.

Re: logging the user once every session
by eric256 (Parson) on May 24, 2004 at 23:26 UTC
    Since you are storing it in a database just query for only those records that match your criteria using SQL. The alternative is to log every hit and include hostname. Then when reporting group by hostname. That way you can gather statistics like unique hits on a daily basis (coming back the next day counts agian), or total hits per month, etc. Databases are powerfull so use that power when trying to find records. You should seldom if ever need to loop threw records to find matchs.

    ___________
    Eric Hodges
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: logging the user once every session
by EvdB (Deacon) on May 25, 2004 at 07:29 UTC
    As you talk about logging you could do an equivalent thing by looking at your server logs. It should be quite easy to count the number of unique hosts hitting your page.

    That said cookies are probably the best way to deal with this though...

    --tidiness is the memory loss of environmental mnemonics