---
title: "Cookie problem"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/15455-cookie-problem"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Alpha II"
published: "2001-03-24T22:21:00.000Z"
updated: "2001-03-29T08:16:00.000Z"
replies: 3
views: 152
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/15455-cookie-problem"
---

# Cookie problem

## #1 — Alpha II, 2001-03-24T22:21Z

Hej!
Jag har gjort ett röstningsscript och när man röstar så ske det sparas en kaka så att man inte ska kunna rösta flera gånger, men det funkar inte.

\[kod\]
\<?php
 setcookie ("voted", "yes",time()+31536000);

if (!isset($voted)) {
  $vfile = fopen("data/poll.txt","r+");
  $antal_ja = str_replace("\\n", "", fgets($vfile, 1024));
  $antal_nej = str_replace("\\n", "", fgets($vfile, 1024));
  fclose($vfile);

if ($vote=="ja") {
 $antal_ja = $antal_ja + 1;
}
elseif ($vote=="nej") {
 $antal_nej = $antal_nej + 1;
}

  $vfile = fopen("data/poll.txt","w+");
  fputs($vfile, "$antal_ja\\n");
  fputs($vfile, "$antal_nej\\n");
  fclose($vfile);
}

header("Location: index.php?id=huvudsidan");
?\>
\[kod\]

Permalänk: https://www.webforum.nu/p/15455

## #2 — Alpha II, 2001-03-25T11:54Z

Ingen som vet varför man kan rösta flera gånger? :q

Permalänk: https://www.webforum.nu/p/317956

## #3 — Alpha II, 2001-03-28T19:23Z

Behöver fortfarande hjälp :l

Permalänk: https://www.webforum.nu/p/317957

## #4 — Agaith, 2001-03-29T08:16Z

Testa med 

```
if ($voted=="yes")
```

som vilkor i första if satsen så fungerar det nog.

Permalänk: https://www.webforum.nu/p/317958

---

Tråden på webben: https://www.webforum.nu/amne/php/15455-cookie-problem
