I'm writing a new plugin that will allow visitor to vote. After a visitor rated a post, I'd like to block double voting. I think the better way to do it is using cookie, but of course I can't insert the code in functions.php or in the theme header. In my case it's better to set cookie via jquery or php?
If you are looking for user only comments then you could try this one ( http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie). This function can be replaced via plugins. If plugins do not redefine these functions, then this will be used instead.
Sets the authentication cookies based User ID.
The $remember parameter increases the time that the cookie will be kept. The default the cookie is kept without remembering is two days. When $remember is set, the cookies will be kept for 14 days or two weeks. but this can only be comment by logged in user. Also if you are using by cookie then you have to ask the client to store the cookies permission by accepting it. ( http://wordpress.org/plugins/cookie-law-info/faq/ ) according to cookie law.
I think you could do with the IP address blocking as well. There are couple of plugin available where you can take idea how they have implement. for eg : WP-PostRatings ( Adds an AJAX rating system for your WordPress blog's post/page. ) I guess this will help you.