用文本文件实现投票系统(一)
简单的文本投票系统 

思路:采用文本的形式解决投票系统的问题
 
步骤:1.首先在您的根目录下建立txt/radio文本文件 
2.在文本文件中写上数据0 0 0(请注意每个0之间有一个空格,最后一个没有!!),0的数目已你的选项而定 
3.建立radioexe.php-处理用户的投票信息  
4.建立radio.php-显示投票信息 源程序: 
/执行文件radioexe.php 

$fp=fopen("txt\radio.txt","r"); 

$filelen=filesize("txt\radio.txt");

$filestring=fgets($fp,$filelen+1); 

fclose($fp); 

//打开文件 

$radio=explode(" ",$filestring); 

//以空格分割每一个变量 

switch($radiobutton)

{

case(1): $radio[0]++; 

break;

case(2): $radio[1]++; 

break; 

case(3):$radio[2]++;

break; }

//判断用户的选择-增加相应的变量值 

$filestring=$radio[2]; 

$filestring=$radio[1]." ".$filestring; 

$filestring=$radio[0]." ".$filestring; 

//echo "$filestring";新的变量 

//写入文本文件 

$fp=fopen("txt\radio.txt","w"); 

fputs($fp,$filestring); 

fclose($fp); 
 
投票显示页面 //如果你的GD库能用的话^^ 

$fp=fopen("txt\radio.txt","r"); 

$filelen=filesize("txt\radio.txt"); 

$filestring=fgets($fp,$filelen+1); fclose($fp); 

$radio=explode(" ",$filestring);

//打开文件 

dl("php_gd.dll"); 

Header( "Content-type: image/gif"); 

$im=imagecreate(30,2);//建立图像标志 $color=imagecolorallocate($im,0,0,0); 

$x2=$radio[0]; 

$y2=2; 

imagefilledrectangle($im,0,2,$x2,$y2,$color); 

imagegif($im); 

注:这里显示的仅仅只是用户的一个选项,您可以更换$radio[x]来得到其它的票数 这里是拥有GD库的朋友解决的办法!下一次我将介绍不用GD库如何解决投票问题^^