版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 程序4-1?php if(!isset($PHP_AUTH_USER) Header(WWW-Authenticate: Basic realm=My Realm); Header(HTTP/1.0 401 Unauthorized); echo Text to send if user hits Cancel buttonn; exit; else echo Hello $PHP_AUTH_USER.; echo You entered $PHP_AUTH_PW as your password.; ? 程序4-2 程序4-3/假设利用文件count.txt保存计数值 程序4-4 程序4-
2、5 程序4-6?php/将数字转化为字符串$strcount = strval($count);$strcount = chop($count);/将数字转化为图形$countlen = strlen($strcount);$strhtml = ;for($I = 0 ; $I $countlen; $s+)$strhtml = $strhtml. ;?程序4-7$file); fclose($fp); $n=6-strlen($num); $out=imagecreate(96,20);/ 建立新图 $im=imagecreatefromgif(0.gif); /取出GIF图形for($i=
3、0;$i$n;$i+) imagecopyresized($out,$im,$i*16,0,0,0,16,20,16,20); /复制新图并调整大小for($j=0;$j$file); display($file); ?程序4-8文件名为:count.php? /计数文件目录$recdir=rec/; /计数文件扩展名$rfile=.txt; if ($len=) /位数$int_width=6; else $int_width=$len; /定义单个数字宽度$count_width=8; /定义单个数字高度$count_height=16; /定义生成与数字09相对应的图形的数据$bitma
4、p =array( 0xff, 0xff, 0xff, 0xc3, 0x99, 0x99, 0x99, 0x99, /* rows 1-8 of 0 */ 0x99, 0x99, 0x99, 0x99, 0xc3, 0xff, 0xff, 0xff, /* rows 9-16 of 0 */ 0xff, 0xff, 0xff, 0xcf, 0xc7, 0xcf, 0xcf, 0xcf, /* rows 1-8 of 1 */ 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xff, 0xff, 0xff, /* rows 9-16 of 1 */ 0xff, 0xff, 0xff
5、, 0xc3, 0x99, 0x9f, 0x9f, 0xcf, /* rows 1-8 of 2 */ 0xe7, 0xf3, 0xf9, 0xf9, 0x81, 0xff, 0xff, 0xff, /* rows 9-16 of 2 */ 0xff, 0xff, 0xff, 0xc3, 0x99, 0x9f, 0x9f, 0xc7, /* rows 1-8 of 3 */ 0x9f, 0x9f, 0x9f, 0x99, 0xc3, 0xff, 0xff, 0xff, /* rows 9-16 of 3 */ 0xff, 0xff, 0xff, 0xcf, 0xcf, 0xc7, 0xc7,
6、0xcb, /* rows 1-8 of 4 */ 0xcb, 0xcd, 0x81, 0xcf, 0x87, 0xff, 0xff, 0xff, /* rows 9-16 of 4 */ 0xff, 0xff, 0xff, 0x81, 0xf9, 0xf9, 0xf9, 0xc1, /* rows 1-8 of 5 */ 0x9f, 0x9f, 0x9f, 0x99, 0xc3, 0xff, 0xff, 0xff, /* rows 9-16 of 5 */ 0xff, 0xff, 0xff, 0xc7, 0xf3, 0xf9, 0xf9, 0xc1, /* rows 1-8 of 6 */
7、0x99, 0x99, 0x99, 0x99, 0xc3, 0xff, 0xff, 0xff, /* rows 9-16 of 6 */ 0xff, 0xff, 0xff, 0x81, 0x99, 0x9f, 0x9f, 0xcf, /* rows 1-8 of 7 */ 0xcf, 0xe7, 0xe7, 0xf3, 0xf3, 0xff, 0xff, 0xff, /* rows 9-16 of 7 */ 0xff, 0xff, 0xff, 0xc3, 0x99, 0x99, 0x99, 0xc3, /* rows 1-8 of 8 */ 0x99, 0x99, 0x99, 0x99, 0x
8、c3, 0xff, 0xff, 0xff, /* rows 9-16 of 8 */ 0xff, 0xff, 0xff, 0xc3, 0x99, 0x99, 0x99, 0x99, /* rows 1-8 of 9 */ 0x83, 0x9f, 0x9f, 0xcf, 0xe3, 0xff, 0xff, 0xff /* rows 9-16 of 9 */ ); if ($id) if (file_exists($recdir$id$rfile) $file=fopen($recdir$id$rfile,r); $num=fread($file,$int_width); fclose($file
9、); $counter = $num+1; $plusfile=fopen($recdir$id$rfile,w); fwrite($plusfile,$counter); fclose($plusfile); else $num=0; for ($i = 0; $i $int_width; +$i) $j = $num % 10; $count$int_width - 1 - $i = $j; $num /= 10; printf(#define counter_width %drn,$count_width * $int_width); printf(#define counter_hei
10、ght %drn,$count_height); printf(static unsigned char counter_bits = rn); for ($i = 0; $i $count_height; +$i) for ($j = 0; $j $int_width; +$j) printf(%s, $bitmap($count$j * $count_height) + $i); if ( $i $count_height - 1) | ($j 程序4-9? /进行计数session_start(); if (session_is_registered(count)=false) whil
11、e($fp=fopen(counter.txt,r+)=false); while(flock($fp,3)=false); $count=fgets($fp,255); $count+=1; fseek($fp,0); fputs($fp,$count); fclose($fp); session_register(count); $len=strlen($count); for($i=1;$i=6-$len;$i+) $imagpath= ; /TEMP为图像文件夹,图像文件名需为0.GIF 9.GIF /显示计数值for($i=1;$i=$len;$i+) $imagpath.=; pr
12、int你是第.$imagpath.位来客; ? 程序4-10文件名为:count.php? Header(Content-type:image/png); $img=ImageCreate(60,20); $link=mysql_pconnect(localhost); mysql_select_db(liarrn,$link); mysql_query(update counter set count=count+1,$link); $str=select count from counter; $result=mysql_query($str,$link); list($counter)=
13、mysql_fetch_row($result); $counter=sprintf(%05d,$counter); for($i=0;$i 程序4-11?php / 发送头信息和创建初始的空白画布 Header( Content-type: image/gif); $image = imagecreate(200,200); / 分配一些颜色 $red = ImageColorAllocate($image,255,0,0); $blue = ImageColorAllocate($image,0,0,255); $white = ImageColorAllocate($image,255,
14、255,255); $grey = ImageColorAllocate($image,200,200,200); / 创建一个初始的灰色矩形用于绘图 ImageFilledRectangle($image,0,0,200,200,$grey); / 连接MySQL服务器并选择数据库 $connect = mysql_connect(,root,); mysql_select_db(graphing,$connect); / 找到结果集中的最大数值 $sql = SELECT MAX(g_num) FROM sales; $maxResult = mysql_query($sql,$conne
15、ct); $max = mysql_result($maxResult,0,0); / 得到公司A的结果集 $sql = SELECT g_num FROM sales WHERE g_team=公司A ORDER BY g_month; $salesResult = mysql_query($sql,$connect); / 找到返回多少列,就是columns的数值 $columns = mysql_num_rows($salesResult); / $x每次增加多少量? $xincrement = bcdiv(200,$columns-1,0); $x=0; / $i 将记录行的数值 $i
16、=0; / 在所有的数据行中循环 while($salesRow=mysql_fetch_array($salesResult) / 像上面所讨论地计算y的坐标值 $y = bcmul(bcdiv($salesRow0,$max,2),200,2); / 在$points数组中增加值 $points$i0 = $x; $points$i1 = $y; / 增加$x的值用$xincrement $x+=$xincrement; / 增加 $i $i+; / 现在在$points数组中循环,此时$i小于$columns-1 for($i=0;$i 程序4-12?php $sql = SELECT
17、g_num FROM sales WHERE g_team=Atlanta ORDER BY g_month; $salesResult = mysql_query($sql,$connect); $columns = mysql_num_rows($salesResult); $xincrement = bcdiv(200,$columns-1,0); $x=0; $i=0; while($salesRow=mysql_fetch_array($salesResult) $y = bcmul(bcdiv($salesRow0,$max,2),200,2); $points$i0 = $x;
18、$points$i1 = $y; $x+=$xincrement; $i+; for($i=0;$i 程序4-13function image($graphdata,$label,$data,$graphwidth,$graphheight,$graphscale,$graphfont,$bg,$text,$grid,$bar,$bz)header(Content-type:image/gif);/创建空白图形 $image=imagecreate($graphwidth+50,$graphheight+50);/分配颜色$bgcolor= imagecolorallocate ($image
19、 ,$bg0,$bg1,$bg2);$textcolor= imagecolorallocate ($image ,$text0,$text1,$text2);$gridcolor=imagecolorallocate ($image ,$grid0,$grid1,$grid2);$barcolor=imagecolorallocate ($image ,$bar0,$bar1,$bar2);$gridabelwidth=imagefontwidth($graphfont)*3+1;$gridableheight= imagefontheight ($graphfont);/绘制直线image
20、line($image,$gridlabelwidth,0,$gridlabelwidth,$graphheight-1,$gridcolor);imageline($image,0,$graphheight-1,$graphwidth-1,$graphheight-1,$gridcolor);for($i=0;$i程序4-14?php /把角度转换为弧度 function radians ($degrees) return($degrees * (pi()/180.0); /取得在圆心为(0,0)的圆上x,y点的值 function circle_point($degrees, $diame
21、ter) $x = cos(radians($degrees) * ($diameter/2); $y = sin(radians($degrees) * ($diameter/2); return (array($x, $y); /填充图表的参数 $ChartDiameter = 200; /图表直径 $ChartFont = 2; /图表字体 $ChartFontHeight = imagefontheight($ChartFont);/图表字体的大小 $ChartData = array( 75,45);/用于生成图表的数据,可通过数据库来取得来确定 $ChartLabel = arra
22、y(yes, no); /数据对应的名称 /确定图形的大小 $ChartWidth = $ChartDiameter + 20; $ChartHeight = $ChartDiameter + 20 + ($ChartFontHeight + 2) * count($ChartData); /确定统计的总数 for($index = 0; $index count($ChartData); $index+) $ChartTotal += $ChartData$index; $ChartCenterX = $ChartDiameter/2 + 10; $ChartCenterY = $Chart
23、Diameter/2 + 10; /创建空白图形 $image = imagecreate($ChartWidth, $ChartHeight); /分配颜色$colorBody = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $colorBorder = imagecolorallocate($image, 0x00, 0x00, 0x00); $colorText = imagecolorallocate($image, 0x00, 0x00, 0x00); $colorSlice = imagecolorallocate($image, 0
24、xFF, 0x00, 0x00); $colorSlice = imagecolorallocate($image, 0x00, 0xFF, 0x00); /图形着色imagefill($image, 0, 0, $colorBody); /绘制扇形 $Degrees = 0; for($index = 0; $index count($ChartData); $index+) $StartDegrees = round($Degrees); $Degrees += ($ChartData$index/$ChartTotal)*360); $EndDegrees = round($Degree
25、s); $CurrentColor = $colorSlice$index%(count($colorSlice); /绘制圆弧 imagearc($image,$ChartCenterX,$ChartCenterY,$ChartDiameter, $ChartDiameter,$StartDegrees,$EndDegrees, $CurrentColor); /画直线 list($ArcX, $ArcY) = circle_point($StartDegrees, $ChartDiameter); imageline($image,$ChartCenterX,$ChartCenterY,f
26、loor($ChartCenterX + $ArcX), floor($ChartCenterY + $ArcY),$CurrentColor); list($ArcX, $ArcY) = circle_point($EndDegrees, $ChartDiameter); imageline($image,$ChartCenterX,$ChartCenterY,ceil($ChartCenterX + $ArcX), ceil($ChartCenterY + $ArcY),$CurrentColor); /填充扇形 $MidPoint = round($EndDegrees - $Start
27、Degrees)/2) + $StartDegrees); list($ArcX, $ArcY) = circle_point($MidPoint, $ChartDiameter/2); imagefilltoborder($image,floor($ChartCenterX + $ArcX),floor($ChartCenterY + $ArcY), $CurrentColor,$CurrentColor); /画边框 imagearc($image, $ChartCenterX, $ChartCenterY, $ChartDiameter, $ChartDiameter, 0, 180,
28、$colorBorder); imagearc($image, $ChartCenterX, $ChartCenterY, $ChartDiameter, $ChartDiameter, 180, 360, $colorBorder); imagearc($image, $ChartCenterX, $ChartCenterY, $ChartDiameter+7, $ChartDiameter+7, 0, 180, $colorBorder); imagearc($image, $ChartCenterX, $ChartCenterY, $ChartDiameter+7, $ChartDiam
29、eter+7, 180, 360, $colorBorder); imagefilltoborder($image, floor($ChartCenterX + ($ChartDiameter/2) + 2), $ChartCenterY, $colorBorder, $colorBorder); for($index = 0; $index 程序4-1516) & 0xff; $G=($color8) & 0xff; $B=($color) & 0xff; return (array($R,$G,$B); / 取得在椭圆心为(0,0)的椭圆上 x, y点的值 function pie_poi
30、nt($deg,$va,$vb) $x= cos(deg2Arc($deg) * $va; $y= sin(deg2Arc($deg) * $vb; return (array($x, $y); /3D饼图类 class Pie3d /声明成员变量var $a; /椭圆长半轴 var $b; /椭圆短半轴 var $DataArray; /每个扇形的数据 var $ColorArray; /每个扇形的颜色要求按照十六进制书写,但前面不加0x,边缘及阴影为黑色 /定义构造函数function Pie3d($pa=100,$pb=60,$sData=100,200,300,400,500, $sC
31、olor=ee00ff,dd0000,cccccc,ccff00,00ccff) $this-a=$pa; $this-b=$pb; $this-DataArray=split(,$sData); $this-ColorArray=split(,$sColor); /定义方法function setA($v) $this-a=$v; function getA() return $this-a; function setB($v) $this-b=$v; function getB() return $this-b; function setDataArray($v) $this-DataArray=split(,$v); function getDataArray($v) return $this-DataArray; function setColorArray($v) $this-ColorArray=split(,$v);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 汽车卸煤沟+-0.000以下施工设计方案
- 盖梁施工设计方案
- 新校区建设项目网喷工程专项施工设计方案
- 植树节活动活动方案策划6篇
- 房地产行业在线选房与虚拟现实看房方案
- 发动机气门间隙的检查调整方法
- 容器编排平台性能优化实践
- 固收转债分析-长高转债定价:上市转股溢价率4348
- 基于桥梁隧道施工常见问题与控制对策
- 2026小升初语文四大名著常识考点附答案
- 2026年西北大学学生就业创业指导服务中心招聘备考题库(3人)附答案详解(基础题)
- 拒绝校园欺凌建造友善和谐校园主题班会
- 中医体质辨识
- 【《基于python的地震数据可视化系统设计》9500字(论文)】
- 规范住院病案首页数据填报工作指南 (2022版)
- 血管解剖知识课件
- 《临床检验技术》课件-尿液结晶
- 2025江苏南京市城建集团所属企业职业经理人招聘1人笔试历年参考题库附带答案详解
- 清除河道施工方案(3篇)
- T/CAPE 10108-2024设备设施报废管理指南
- 《康复医学概论》课件-第三章 残疾学
评论
0/150
提交评论