صفحه ای در سرور که توسط جاوا اسکریپت بالا فراخوانی شده است یک فایل PHP به نام "poll_vote.php" است:
<?php
$vote = $_REQUEST['vote'];
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$yes = $array[0];
$no = $array[1];
if ($vote == 0) {
$yes = $yes + 1;
}
if ($vote == 1) {
$no = $no + 1;
}
//insert votes to txt file
$insertvote = $yes."||".$no;
$fp = fopen($filename,"w");
fputs($fp,$insertvote);
fclose($fp);
?>
<h2>Result:</h2>
<table>
<tr>
<td>Yes:</td>
<td>
<img src="poll.gif"
width='<?php echo(100*round($yes/($no+$yes),2)); ?>'
height='20'>
<?php echo(100*round($yes/($no+$yes),2)); ?>%
</td>
</tr>
<tr>
<td>No:</td>
<td>
<img src="poll.gif"
width='<?php echo(100*round($no/($no+$yes),2)); ?>'
height='20'>
<?php echo(100*round($no/($no+$yes),2)); ?>%
</td>
</tr>
</table>
مقدار از جاوا اسکریپت و موارد زیر ارسال می شود
اتفاق می افتد:
- محتوای فایل "poll_result.txt" را دریافت کنید
- محتوای فایل را در متغیرها قرار دهید و یکی را به متغیر انتخابی اضافه کنید
- نتیجه را در فایل "poll_result.txt" بنویسید
- یک نمایش گرافیکی از نتیجه نظرسنجی را خروجی بگیرید