neseleik's avatar

What is the best way to manage an unregistered visitor rating system? Token? IP??

Hi all, I want my website visitor to be able to tell me by two simple button if some post are 'Usefull' or 'Useless', like thumbs.

I know some packages could do this with some lines of code but I also want with this system to learn some relationship tricks.

Only my post will be "rateable", so I think I don't need a polymorphic structure. What I have in mind: Rate table with: a token cookie or an IP, or twice?? post_id rate (boolean: 1 = usefull, 0 = useless)

Rate model belongsTo Post Post model hasMany Rate Liteblue

My question is: what is the best way to store "unique" visitor in my table? a token? the IP address of visitor? twice? something else? Maybe Laravel includes some magic tricks to catch "unique visitor which have already rate post"? I welcome any advice which could help me.

Thanks

0 likes
1 reply
fylzero's avatar

@neseleik I would do a hash off the ip and domain. The domain will be helpful to make sure they are actually using your site. It won't be perfect, but it should do a decent job of keeping things honest.

This is what Laravel does for tracking throttled login requests...

protected function resolveRequestSignature($request)
    {
        if ($user = $request->user()) {
            return sha1($user->getAuthIdentifier());
        }

        if ($route = $request->route()) {
            return sha1($route->getDomain().'|'.$request->ip());
        }

        throw new RuntimeException('Unable to generate the request signature. Route unavailable.');
    }

Basically they are getting the domain and ip and wrapping that up in a sha1 hash to generate a unique key for a not logged in visitor.

return sha1($route->getDomain().'|'.$request->ip());
24 likes

Please or to participate in this conversation.