Hi Srini,
If you open a new window, and set a cookie there, simply closing the window leaving you with the already opened parent window won't do you any good at all.
The cookie will only be active for the next page, e.g.
open page 1
set cookie
redirect to page 2
Then, on page 2 the cookie is active and alive. You can then check.
What you are doing is:
open page 1
user clicks on something in page 1
page 2 opens in a new window
page 2 sets cookie
page 2 closes
still open and unchanged page 1 is supposed to check the cookie that was set in the briefly opened new window.
That will not work, or perhaps I'm wrong, but in my honest opinion, you should bear in mind, that page 1 with your poll links, has already been loaded before any cookie was set, e.g. it was already parsed.
In other words, as far as page 1 is concerned, the cookies are still unset, and the user can revote as much as he likes.
The only thing that will make page 1 understand you cannot vote, e.g. re-read the cookies for being set or not, is to force a reload from your script of page 1 from some other page.
Perhaps there is a nice way to work around this, but I think this will be quite something to do.
What perhaps could work...
Create a javascript to set the cookie and capture the "OnClick" event when the user clicks a link. Before the click is handled, carry out a function to set a cookie for that particular vote, then javascript code to open a new window to display poll.
On the new window, you can php code to check for the cookie and decide to offer the user to vote or not.
Something like this on page 1:
<script language="javascript" type="text/css">
function setcookie(iPollid) {
[set cookie for poll id iPollid]
[open new window]
}
</script>
echo "<a href=\"#\" Onclick=\"setcookie($pollid);\">Click for Poll $pollid</a>";
There are however 2 problems with this:
- Even if the user decides to not vote after all, his vote is logged and he can no longer vote
- If the user disables javascript, what then?
Note; the code is not meant for real use, it's just to show you the general idea ;-) I can program but so many hours before my mind starts messing up ;-)