radio-welt
Grünschnabel
Ich habe auf einer Seite ein Voting Script bzw. Tutorial gefunden. Ich habe alles so eingestellt, wie es in der Anleitung stand, aber es zeigt, wenn man auf den Votebutton klickt immer diesen Fehler an:
Was muss ich ändern?
Dies ist der Code der Seite (script.php):Warning: Cannot modify header information - headers already sent by (output started at /users/radio-welt/www/index.php:161) in /users/radio-welt/www/script.php on line 79
PHP:
<?PHP
require_once "config.vote.php";
$vote = new Vote($votevars);
#Ermitteln, ob Formulardaten gepostet wurden
if(!empty($_POST['um_vote'])) {
#Wenn Postdaten den erforderlichen Werten entsprechen ((int) zwischen 0 und 11)
if ( (int) $_POST['um_vote'] > 0 && (int) $_POST['um_vote'] < 11 ) {
#überprüfen, ob Doppelpost
$vote->getIP();
$vote->checkDblVote($votevars);
if ( (bool) $vote->dblvote === true) {#Wenn Doppelvote
$vote->setTextausgabe("text_dblvote");
} else { #wenn nicht Doppelpost
#IP ermitteln, Cookie setzen und IP/VoteID/Zeit speichern, sowie den Vote speichern
$vote->setCookie($votevars);
$vote->saveToBlocklist($votevars);
$vote->increaseVote();
$vote->saveVote($votevars);
$vote->setTextausgabe("text_thnx");
}
} else { #Postdaten entsprechen nicht den erforderlichen Werten
die("Die Übermittelten Daten entsprechen nicht den Vorgaben. Benutzen Sie bitte den Zurückbutton Ihres
Browser und bewerten Sie erneut.");
}
}
$vote->setVotebox($votevars);
$ausgabe = $vote->votebox;
#######################################################################
# Beginn Klasse Vote #
#######################################################################
class Vote {
protected $votelist;
protected $savetime;
protected $ip;
protected $tempIP;
protected $blocklist;
protected $id_found;
protected $case;
protected $temp;
function __construct($votevars) {
#Variablen Setzen
$this->votelist_id = ($_SERVER['REQUEST_URI']);
$this->votelist_id = str_replace("{$_SERVER['SERVER_NAME']}///", "", $this->votelist_id);
$this->votelist_id = str_replace("=", "_", $this->votelist_id);
$this->votelist_id = str_replace(".", "_", $this->votelist_id);
$this->votelist_id = str_replace("?", "_", $this->votelist_id);
$this->votelist_count = 0;
$this->votelist_value = 0;
$this->textausgabe = "text_stnd";
#Vote Formular Template einlesen
if (file_exists($votevars['votetemplate'])) {
$this->votebox = file_get_contents($votevars['votetemplate']);
} else {
die("Datei {$votevars['votetemplate']} nicht gefunden.");
}
#Vote Daten einlesen, wenn vorhanden
if (file_exists($votevars['votelist'])) {
$votelist = file($votevars['votelist']);
} else {
die("Datei {$votevars['votelist']} nicht gefunden.");
}
#Wenn Vote Daten gespeichert, diese für aufgerufene Seite ausgeben, wenn vorhanden
if (!empty($votelist)) {
foreach($votelist as $k => $v) {
$votelist[$k] = explode(" ++ ", $votelist[$k]);
if ($this->votelist_id == $votelist[$k][0]) {
$this->votelist_count = $votelist[$k][1];
$this->votelist_value = $votelist[$k][2];
}
$votelist[$k] = implode(" ++ ", $votelist[$k]);
}
$this->votelist = $votelist;
}
} #ENDE Konstruktor
function setCookie($votevars) {
setcookie($this->votelist_id, "voted", time()+(60*60*$votevars['blocktime']), "/", ".{$_SERVER['SERVER_NAME']}");
}
function checkDblVote($votevars) {
$this->dblvote = false;
if($_COOKIE[$this->votelist_id] == "voted") { #Cookie für diesen Eintrag existiert->Doppelvote
$this->dblvote = true;
return;
} else { #Cookie für diesen Eintrag existiert nicht->Blockliste einlesen
if (!file_exists($votevars['blocklist'])) {
die("Die Datendatei für die IP-Sperre: \"{$votevars['blocklist']}\" konnte nicht gefunden werden");
} else {
$this->blocklist = file($votevars['blocklist']);
#Blockliste überprüfen->wenn Doppelpost dblvote=TRUE
foreach ($this->blocklist as $k => $w) {
#IP und ID vorhanden -> timestamp abgleichen
if (stristr($this->blocklist[$k], $this->IP) && stristr($this->blocklist[$k], " {$this->votelist_id} " )) {
$savetime = $this->blocklist[$k];
$savetime = explode(" ++ ", $savetime);
if (time() - $savetime[2] > 60*60*$votevars['blocktime']) {
array_splice($this->blocklist, $k, 1);
} else {
$this->dblvote = true;
break;
}
}
}
}
}
}
function increaseVote() {
$this->votelist_value = ($this->votelist_value*$this->votelist_count+$_POST['um_vote'])/($this->votelist_count+1);
$this->votelist_count ++;
}
function getIP() {
unset($ip);
if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
$tempIP = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = $tempIP[0];
} else {
if ($_SERVER['HTTP_CLIENT_IP']) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
}
if (!empty($ip)) {
$this->IP = ($ip);
} else {
$this->IP = ("0.0.0.0");
}
}
function saveToBlocklist($votevars) {
#Wenn Einträge vorhanden, säubern zu alter Einträge (doppelt hält besser ;) )
$blocklist = array();
foreach ($this->blocklist as $k => $w) {
$w = trim($w);
if (!empty($w)) {
$blocklist[] = $w;
}
}
if (!empty($blocklist)) {
$temp = array();
foreach ($blocklist as $k => $w) {
$blocklist[$k] = explode(" ++ ", $blocklist[$k]);
if (time() - $blocklist[$k][2] < 60*60*$votevars['blocktime']) {
$temp[] = implode(" ++ ", $blocklist[$k]);
}
}
$blocklist = $temp;
}
#Neue Daten anfügen
$blocklist[] = $this->IP." ++ ".$this->votelist_id." ++ ".time();
$blocklist = implode("\n", $blocklist);
#Blockliste speichern
$fp = fopen($votevars['blocklist'], "wb");
flock($fp, LOCK_EX);
fwrite($fp, $blocklist);
flock($fp, LOCK_UN);
fclose($fp);
}
function saveVote($votevars) {
$id_found = false;
#Datendatei öffnen
if (!file_exists($votevars['votelist'])) {
die("Die Datendatei für die Wertungsdaten: \"{$votevars['votelist']}\" konnte nicht gefunden werden");
} else {
$this->votelist = file($votevars['votelist']);
}
#Backup speichern?
if (time() - filemtime($votevars['votelist'].".bak") > 60*60*$votevars['backuptime']) {
if (!file_exists($votevars['votelist_bak'])) {
die("Die Sicherungsdatei für die Wertungsdaten: \"{$votevars['votelist_bak']}\" konnte nicht gefunden werden");
} else {
$fp = fopen($votevars['votelist'].".bak", "wb");
flock($fp, LOCK_EX);
fwrite($fp, file_get_contents($votevars['votelist']));
flock($fp, LOCK_UN);
fclose($fp);
}
}
#Zeile mit aktueller vote_ID suchen und neue Werte eintragen
foreach ($this->votelist as $k => $w) {
if (stristr($this->votelist[$k], "{$this->votelist_id} ")) {
$this->votelist[$k] = explode(" ++ ", $this->votelist[$k]);
$this->votelist[$k][1] = $this->votelist_count;
$this->votelist[$k][2] = $this->votelist_value;
$this->votelist[$k] = implode(" ++ ", $this->votelist[$k]);
$id_found = true;
break;
}
}
if ( (bool) $id_found === false) {
$this->votelist[] = trim($this->votelist_id)." ++ ".trim($this->votelist_count)." ++ ".trim($this->votelist_value);
}
$temp = array();
foreach ($this->votelist as $k => $w) {
$w = trim($w);
if (!empty($w)) {
$temp[] = $w;
}
}
if (count($temp) >= 2) {
sort($temp);
}
$this->votelist = $temp;
$this->votelist = implode("\n", $this->votelist);
#aktualisierte Datei speichern
$fp = fopen($votevars['votelist'], "wb");
flock($fp, LOCK_EX);
fwrite($fp, $this->votelist);
fclose($fp);
}
function setVotebox($votevars) {
$vote_bar_width = $this->votelist_value*10;
$this->votelist_value = sprintf("%.2f", $this->votelist_value);
$this->votelist_value = str_replace(".", ",", $this->votelist_value);
$this->votebox = str_replace("[%vote_value%]", $this->votelist_value, $this->votebox);
$this->votebox = str_replace("[%vote_bar_width%]", $vote_bar_width, $this->votebox);
$this->votebox = str_replace("[%vote_count%]", $this->votelist_count, $this->votebox);
$this->votebox = str_replace("[%vote_text%]", $votevars[$this->textausgabe], $this->votebox);
}
function setTextausgabe($case) {
$this->textausgabe = $case;
}
} #ENDE Klasse Vote
?>