Анкета

human

Registered
Код:
<?php

include("lp_settings.inc"); //include file containing general settings

function SumArray($arr) {
	$h=count($arr); $in=0; $m=0;
	while ($in<$h) { $m += $arr[$in]; $in++;	}
	return $m;
}

function ReadElements() {
	global $filename;
	$fp=fopen($filename, "r");
	$file_contents=fread($fp,filesize($filename)-1);
	fclose($fp);
	$elements=explode(":",$file_contents);
	$h=(count($elements)-1)/2;
	$question=$elements[0];
	$in=0;
	while ($h>$in) {
		$item[$in]=$elements[(2*$in+1)];
		$itemvoted[$in]=$elements[(2*$in+2)];
		$in++;
	}
	return array ($item, $itemvoted, $question);
}

list ($item, $itemvoted, $question) = ReadElements();

if(isset($pollidcookie)) {
	if ($question != $pollidcookie) {
	$votingstep=1;
	}
}
setcookie("pollidcookie", $question, time()+$time_between_votes);


if (isset($votingstep)) {
	 function ShowTheStuff($item, $itemvoted, $graph_width, $graph_height) {
		$hector=count($itemvoted);$totalvotes=0;$in=0;$stepstr='';
		$totalvotes=SumArray($itemvoted);
		$in=0;
		if ($totalvotes==0) { $totalvotes=0.0001; }
		while ($in<$hector) {
			$stepstr=$stepstr.$item[$in].': '.(int)(($itemvoted[$in]/$totalvotes)*100).'%<br>';
			$timesred=(int)((($itemvoted[$in]/$totalvotes))*$graph_width);
			$stepstr=$stepstr.'<img height='.$graph_height.' width='.$timesred.' src="lp_1.gif"><img height='.$graph_height.' width='.($graph_width-$timesred).' src=""><br><br>';
			$in++;
		}
		return $stepstr;
	}
}

if (!isset($votingstep)) {
	$votingstep=1;
	}

if ($votingstep==2) {
	if(!isset($radios)){
		$votingstep=1;
	} // detect if someone has clicked the voting button without choosing an item
}

if ($votingstep==1) {
	setcookie("votingstep","2",time()+$time_between_votes);
	$mainstr=$message1;
	$step1str='<form action="'.$callingfile.'" method="post" name="form1">';
	$totalvotes=SumArray($itemvoted);
	$in=0;
	$datop=count($item);
	while($in<$datop){
		$step1str=$step1str.'<input type="radio" name="radios" value="'.$in.'"> '.$item[$in].'<br>';
		$in++;
	}
	$step1str=$step1str.'<br><input style="'.$buttonstyle.'" type="Submit" value="'.$vote_str.'"></form>';
}
if ($votingstep==2) {
	setcookie("votingstep","3",time()+$time_between_votes);
	$mainstr=$message2;
	$itemvoted[$radios]=$itemvoted[$radios]+1;
	$totalvotes=SumArray($itemvoted);
	$fp=fopen($filename, "w");
	$hector=count($item);
	$in=0;
	$linetoadd=$question.':';
	fputs($fp, $linetoadd);
	while($in<$hector) {
		$linetoadd=$item[$in].':'.$itemvoted[$in].':';
		fputs($fp, $linetoadd);
		$in++;
	}
	fclose($fp);
	$step2str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}
if ($votingstep==3) {
	$mainstr=$message3;
	$totalvotes=SumArray($itemvoted);
	$step3str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}



?>

Ето това е кода.Някой може ли да ми каже, заедно с бисквитките да записва и IP-то на потребителя, който е гласувал?
 
Ако никой не знае да са двете(и ИП и бисквитки) да каже поне как ще е само с ИП
 
Присвоява IP-то на променливата
Код:
$ipaddress = getenv("REMOTE_ADDR");

Претърсва IP.inc и ако намери съществуващо IP изписва съобщение че вече е гласувано

Код:
if (file_exists("ip.inc")) 
{ 
$ip= file("ip.inc"); 
$n=count($ip); 
for ($i=0; $i<$n;$i++) 
{ 
if (eregi($ipaddress,$ip[$i])) 
{ 
echo "Вие сте гласували<br>";

Записва IP-то на нов ред в IP.inc
Код:
$zapisip=$ipaddress."\n";
Отваря IP.inc
Код:
$fp = fopen ( "ip.inc" ,"a");
Записва IP-то вътре
Код:
fwrite($fp, $zapisip );
Затваря IP.inc
Код:
fclose($fp);
 
Кода го направих
Код:
<?php
$ipaddress = getenv("REMOTE_ADDR");
include("lp_settings.inc"); //include file containing general settings

function SumArray($arr) {
	$h=count($arr); $in=0; $m=0;
	while ($in<$h) { $m += $arr[$in]; $in++;	}
	return $m;
}

function ReadElements() {
	global $filename;
	$fp=fopen($filename, "r");
	$file_contents=fread($fp,filesize($filename)-1);
	fclose($fp);
	$elements=explode(":",$file_contents);
	$h=(count($elements)-1)/2;
	$question=$elements[0];
	$in=0;
	while ($h>$in) {
		$item[$in]=$elements[(2*$in+1)];
		$itemvoted[$in]=$elements[(2*$in+2)];
		$in++;
	}
	return array ($item, $itemvoted, $question);
}

list ($item, $itemvoted, $question) = ReadElements();

if(isset($pollidcookie)) {
	if ($question != $pollidcookie) {
	$votingstep=1;
	}
}
setcookie("pollidcookie", $question, time()+$time_between_votes);
if (file_exists("ip.inc")) 
{ 
$ip= file("ip.inc"); 
$n=count($ip); 
for ($i=0; $i<$n;$i++) 
{ 
if (eregi($ipaddress,$ip[$i])) 
{ 
	 function ShowTheStuff($item, $itemvoted, $graph_width, $graph_height) {
		$hector=count($itemvoted);$totalvotes=0;$in=0;$stepstr='';
		$totalvotes=SumArray($itemvoted);
		$in=0;
		if ($totalvotes==0) { $totalvotes=0.0001; }
		while ($in<$hector) {
			$stepstr=$stepstr.$item[$in].': '.(int)(($itemvoted[$in]/$totalvotes)*100).'%<br>';
			$timesred=(int)((($itemvoted[$in]/$totalvotes))*$graph_width);
			$stepstr=$stepstr.'<img height='.$graph_height.' width='.$timesred.' src="lp_1.gif"><img height='.$graph_height.' width='.($graph_width-$timesred).' src="lp_0.gif"><br><br>';
			$in++;
		}
		return $stepstr;
	}
}

if (!isset($votingstep)) {
	$votingstep=1;
	}

if ($votingstep==2) {
	if(!isset($radios)){
		$votingstep=1;
	} // detect if someone has clicked the voting button without choosing an item
}

if ($votingstep==1) {
	setcookie("votingstep","2",time()+$time_between_votes);
	$mainstr=$message1;
	$step1str='<form action="'.$callingfile.'" method="post" name="form1">';
	$totalvotes=SumArray($itemvoted);
	$in=0;
	$datop=count($item);
	while($in<$datop){
		$step1str=$step1str.'<input type="radio" name="radios" value="'.$in.'"> '.$item[$in].'<br>';
		$in++;
	}
	$step1str=$step1str.'<br><input style="'.$buttonstyle.'" type="Submit" value="'.$vote_str.'"></form>';
}
if ($votingstep==2) {
	setcookie("votingstep","3",time()+$time_between_votes);
	$mainstr=$message2;
	$itemvoted[$radios]=$itemvoted[$radios]+1;
	$totalvotes=SumArray($itemvoted);
	$fp=fopen($filename, "w");
	$hector=count($item);
	$in=0;
	$linetoadd=$question.':';
	fputs($fp, $linetoadd);
	while($in<$hector) {
		$linetoadd=$item[$in].':'.$itemvoted[$in].':';
		fputs($fp, $linetoadd);
		$in++;
	}
	fclose($fp);
	$step2str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}
if ($votingstep==3) {
	$mainstr=$message3;
	$totalvotes=SumArray($itemvoted);
	$step3str=ShowTheStuff($item, $itemvoted, $graph_width, $graph_height);
}

$zapisip=$ipaddress."\n";
$fp = fopen ( "ip.inc" ,"a");
fwrite($fp, $zapisip );
fclose($fp);
?>

И сега дава ерор
Parse error: parse error, unexpected $ in /home/www/bukhum6.freehostia.com/poll/lp_source.php on line 111
 

Back
Горе