在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<? //用COOKIE保存投票人的投票记录 if($vote && !$already_voted) SetCookie("already_voted","1"); ?> <html> <head> <title>简易投票系统</title> </head> <body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF"> <br><center><font color=green>简易投票系统-学习PHP 4.0容易吗?</font></center><br> <table cellspacing=0 bordercolordark=#FFFFFF width="60%" bordercolorlight=#000000 border=1 align="center" cellpadding="2"> <tr> <td align="center"> <form action="<?echo $PHP_SELF?>" method="post" name="frmVote"> <br>添加一个投票类别: <input type="text" name="newvoteitem" size="20" maxlength="30"><input type=submit value="添 加"><br><br> <? //连接数据库 mysql_connect("localhost","root",""); $mysqldb="test"; if($newvoteitem) { //添加新的投票项 if(!mysql_db_query($mysqldb,"insert into vote values ('$newvoteitem',0)")) { echo "添加出错!<br>"; } } //用COOKIE保存投票人的投票记录 if($vote && $already_voted) { echo "<font color=red>请您不要重复投票,谢谢!</font><br><br>\n"; } else if($vote) { if(!mysql_db_query($mysqldb,"update vote set votes=votes+1 where name='$vote'")) { echo "投票出错!<br>"; } } //计算总投票数 $result=mysql_db_query($mysqldb,"select sum(votes) as sum from vote"); if($result) { $sum=(int) mysql_result($result,0,"sum"); mysql_free_result($result); } //读出投票项数据 $result=mysql_db_query($mysqldb,"select * from vote order by votes DESC"); ?> <table cellspacing=0 bordercolordark=#FFFFFF width="90%" bordercolorlight=#000000 border=1 align="center" cellpadding="2"> <tr> <td align="center" width="15%">投票</td> <td align="center" width="60%">选项</td> <td align="center" width="25%">票数/比例</td> </tr> <? //循环读出投票项 while($row=mysql_fetch_row($result)) { //计算百分比 $per=(int)(100*$row[1]/$sum); ?> <tr> <td align="center"><input type=radio name=vote value="<?echo $row[0]?>"></td> <td><?echo $row[0]?></td> <td align="right"><?echo $row[1]?><img src="blue.gif" height=10 width="<?echo $per?>"><?echo $per?></td> </tr> <? } //释放结果集 mysql_free_result($result); ?> </table> <br><input type=submit value="投 票"> </form> </td> </tr> </table> </BODY> </HTML> <? require("config.php"); $sqldo="select count(*) as title from $mytable where sub_id<1"; $result=mysql_query($sqldo); $message_count=mysql_result($result,0,"title"); ?> <table border="0" width="75%" cellspacing="0" cellpadding="0" align="center"> <tr bgcolor="FFEAA2"> <td width="100%" height="18" valign="bottom" align="right">留言总数:<font color=red><?echo $message_count?></font> | <a href="guestbook.php">看留言</a> </td> </tr> </table> <? if ($doadd) { $name=htmlspecialchars($name); $email=htmlspecialchars($email); $comefrom=htmlspecialchars($comefrom); $homepage=htmlspecialchars($homepage); $icq=htmlspecialchars($icq); $oicq=htmlspecialchars($oicq); $image=htmlspecialchars($image); $comment=htmlspecialchars($comment); if ($name&&$comment) { $add_time=date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s"); $result=mysql_query("insert into $mytable (sub_id,name,email,comefrom,homepage,icq,oicq,image,comment,password,add_time) values ('$sub_id','$name','$email','$comefrom','$homepage','$icq','$oicq','$image','$comment','$password','$add_time')"); if ($notify) { $message="$comment\n\n$name $email\n\n$add_time"; mail($admin_email, "有新的留言: ".$name, $message, "From: ".$email."\nReply-To: ".$email."\nX-Mailer: PHP/" . phpversion()); } echo "<p align=\"center\">您的留言发送成功,谢谢!<a href=\"guestbook.php\">查看留言请返回</a></p>\n"; } else { echo "<p align=\"center\">姓名和内容必须填写!<a href=\"JavaScript:history.back()\">返回</a></p>\n"; } } else { if ($reply&&$recid) { echo "<p align=\"center\">回复留言</p>"; $sub_id="<input type=\"hidden\" name=\"sub_id\" value=\"$recid\">"; } else { echo "<p align=\"center\">填写留言</p>"; } echo "<form method=\"POST\" action=\"add.php\"> <table border=\"0\" width=\"75%\" align=\"center\"> <tr> <td> <div align=\"center\"> <table border=\"0\" width=\"80%\" cellpadding=\"20\" cellspacing=\"0\"> <tr> <td width=\"100%\" bgcolor=\"FFFBEC\">姓名: <input type=\"text\" name=\"name\" size=\"25\">$sub_id 电子邮件: <input type=\"text\" name=\"email\" size=\"25\"><br> 来自: <input type=\"text\" name=\"comefrom\" size=\"25\"> 主页地址: <input type=\"text\" name=\"homepage\" size=\"25\"><br> OICQ: <input type=\"text\" name=\"oicq\" size=\"25\"> <p>表情: "; $con=1; while ( list( $key, $val ) = each( $images ) ) { $checked=""; if ($con==1) { $checked=" checked"; $con=0; } echo "<input type=\"radio\" value=\"$key\" name=\"image\"$checked><img border=\"0\" src=\"$imgdir/$key\" alt=\"$val\"> "; } echo "</p>\n <p><b>留言:</b><br> <textarea rows=\"4\" name=\"comment\" cols=\"72\"></textarea></p> <p><input type=\"submit\" value=\"发送留言\" name=\"doadd\"> <input type=\"reset\" value=\"擦掉重写\" name=\"B2\"></td> </tr> </table> </div> </td> </tr> </table> </center> </div> </form> "; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>PHP4.0 +MYSQL 留言本</title> <style type="text/css"> <!-- input { font-size:9pt; } A:link {text-decoration: underline; font-size:9pt;color:000059} A:visited {text-decoration: underline; font-size:9pt;color:000059} A:active {text-decoration: underline; font-size:9pt} A:hover {text-decoration:underline;color:red} body,table {font-size: 9pt} tr,td{font-size:9pt} --> </style> </head> <body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF"> <center><font color=red size=6>PHP4.0+MYSQL 留言本</font></center><br> <? $dbuser=mysql_connect('localhost','root',''); $mydb=mysql_select_db('test',$dbuser); $mytable="guestbook"; // 表名 $page_size=8; $notify=1; $imgdir="images"; $images=array( "say.gif" => "随便说说", "happy.gif" => "高兴", "sad.gif" => "悲伤", "toohappy.gif" => "大笑", "wilk.gif" => "眨眼", "warning.gif" => "警告", "question.gif" => "问题", "reply.gif" => "回答", "attention.gif" => "注意", "agree.gif" => "同意", "other.gif" => "号外" ); ?> <? require("config.php"); if (!$page) { $page=1; } $sqldo="select count(*) as title from $mytable where sub_id<1"; $result=mysql_query($sqldo); $message_count=mysql_result($result,0,"title"); $page_count=ceil($message_count/$page_size); $offset=($page-1)*$page_size; $sqldo="select * from $mytable where sub_id<1 order by id desc limit $offset, $page_size"; $result=mysql_query($sqldo); ?> <table border="0" width="70%" cellspacing="0" cellpadding="0" align="center"> <tr bgcolor="FFEAA2"> <td width="100%" height="18" valign="bottom" align="right">留言总数:<font color=red><?echo $message_count?></font> | <a href="add.php">写留言</a> </td> </tr> </table> <br> <table border="0" width="70%" cellspacing="0" cellpadding="0" align="center"> <? if($result) { while($myrow=mysql_fetch_array($result)) { listtopic($myrow,"70%",1); $sqldo2="select * from $mytable where sub_id=$myrow[id] order by add_time"; $result2=mysql_query($sqldo2); if($result2) { $rows2=mysql_num_rows($result2); if($rows2) { ?> <tr> <td width="100%"> <table border="0" width="100%" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="5%" bgcolor="FFFECC" align="center">回<br>复</td> <td width="95%"> <? while($myrow2=mysql_fetch_array($result2)) { listtopic($myrow2,"100%",0); echo " </table>"; } ?> </td> </tr> </table> </td> </tr> <? } } echo " </table> <br> "; } $prev_page=$page-1; $next_page=$page+1; echo " <p align=\"center\">| "; if ($page<=1){ echo "第一页 | "; } else{ echo "<a href='$PATH_INFO?page=1'>第一页</a> | "; } if ($prev_page<1){ echo "上一页 | "; } else{ echo "<a href='$PATH_INFO?page=$prev_page'>上一页</a> | "; } if ($next_page>$page_count){ echo "下一页 | "; } else{ echo "<a href='$PATH_INFO?page=$next_page'>下一页</a> | "; } if ($page>=$page_count){ echo "最后一页 |</p>\n"; } else{ echo "<a href='$PATH_INFO?page=$page_count'>最后一页</a> |</p>\n"; } } function listtopic($myrow,$this_table_width,$is_reply) { global $imgdir; $comment=nl2br($myrow[comment]); if ($myrow[email]) { $line1_left="<img border=\"0\" src=\"$imgdir\\$myrow[image]\"> <a href=\"mailto:$myrow[email]\">$myrow[name]</a>"; } else { $line1_left="<img border=\"0\" src=\"$imgdir\\$myrow[image]\"> $myrow[name]"; } if ($myrow[comefrom]) { $line1_left .= " 来自: $myrow[comefrom]"; } else { $line1_right=""; } if ($myrow[oicq]) { $line1_right .= " <img border=\"0\" src=\"$imgdir\\oicq.gif\" alt=\"OICQ:$myrow[oicq]\">"; } if ($myrow[homepage]) { $line1_right .= " <a href=\"$myrow[homepage]\" target=\"_blank\"><img border=\"0\" src=\"$imgdir\\homepage.gif\" alt=\"主页:$myrow[homepage]\"></a>"; } if ($is_reply) { $toolsbar="<a href=\"add.php?reply=1&recid=$myrow[id]\" $table_head_bodystyle>回复</a> "; } $toolsbar .= "修改 删除 "; ?> <table border="0" width="<?echo $this_table_width?>" align="center"> <tr> <td width="100%" bgcolor="fff8d9"> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="50%"><?echo $line1_left?></td> <td width="50%" align="right"><?echo $line1_right?> </td> </tr> </table> </td> </tr> <tr> <td width="100%" bgcolor="FFFBEC"><?echo $comment?></td> </tr> <tr> <td width="100%" bgcolor="FFFBEC"> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="50%">留言时间:<?echo $myrow[add_time]?></td> <td width="50%" align="right"><?echo $toolsbar?></td> </tr> </table> </td> </tr> <? } ?> <? // 本例来自与ZEND网站,由HUNTE整理 if($action1){ //如果文件上传,进行处理 ?> <html> <head> <title>多文件上传</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body bgcolor="#FFFFFF" text="#000000"> <p><font face="Arial, Helvetica, sans-serif"><font size="+1">文件上传处理</font><br><br> <? set_time_limit(60); // 以确保较大文件上传 $path1 = dirname($PATH_TRANSLATED)."/upload/"; //输出上传路径; //print $path1."<br>"; // assign our path in a form PHP for Windows understands for($i=1;$i<3;$i++) { $temp1="file".$i; $temp2="file".$i."_name"; $source=$$temp1; $source_name=$$temp2; // print $temp."=".$$temp."<br>"; //print $file1_name; //print $file2_name; //exit; //***************** //$source = $file1; //$source_name = $file1_name; //print $source."<br>"; //print $source_name; //exit; if(($source <> "none")&&($source <> "")) { // see if the file exists; non-existing file has name of "none" if($error1 <> 1) { // no need to copy a file if directory not write-enabled $dest = $path1.$source_name; // append file name to our path if(copy($source,$dest)){ // copy the file from the temp directory to the upload directory, and test for success echo "$source has been uploaded<br>\n"; $imagesize = getimagesize($dest); switch($imagesize[2]) { case 0: echo "<br> Image is a unknown <br>"; //unlink($dest); exit; case 1: echo "<br> Image is a GIF <br>"; echo "$dest has a width of $imagesize[0]<br>"; echo "$dest has a height of $imagesize[1]<br>"; $newname = $path1; $newname .=$i.time() . ".gif"; if(copy($dest,$newname)) { //echo "<br> GIF Rename Successful from $dest to $newname"; }else { //echo "<br> GIF Rename Unsuccessful"; } //unlink ($dest); break; case 2: echo "<br> Image is a JPG <br>"; echo "$dest has a width of $imagesize[0]<br>"; echo "$dest has a height of $imagesize[1]<br>"; $newname = $path1; $newname .=$i.time() . ".jpg"; if(copy($dest,$newname)) { //echo "<br> JPG Rename Successful from $dest to $newname"; }else { //echo "<br> JPG Rename Unsuccessful"; } //unlink ($dest); break; case 3: echo "<br> Image is a PNG <br>"; echo "$dest has a width of $imagesize[0]<br>"; echo "$dest has a height of $imagesize[1]<br>"; $newname = $path1; $newname .=time() . ".png"; if(copy($dest,$newname)) { //echo "<br> PNG Rename Successful from $dest to $newname"; }else { //echo "<br> PNG Rename Unsuccessful"; } //unlink ($dest); break; } }else { echo "Upload directory not write-enabled\n"; // you need to write-enable the upload directory $error1 = 1; // set flag } } //unlink($source); // delete the file from the temp directory } ?> <image src="upload/<? print basename($newname)?>"> <? } //end for ?> <br><a href="90.php">Back</a> </font></p> </body> </html> <? } else { ?> <html> <head> <title>多文件上传</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body bgcolor="#FFFFFF" text="#000000"> <p><font face="Arial, Helvetica, sans-serif"><font size="+1">File Upload</font><br><br> If your browser is upload-enabled, you will see "Browse" (Netscape, Internet Explorer) or ". . ." (Opera) buttons below. Use them to select file(s) to upload, then click the "Upload" button. After the files have been uploaded, you will see a results screen.<br> <form method="post" enctype="multipart/form-data" action="90.php"> <input type="hidden" name="MAX_FILE_SIZE" value="800000"> <input type="hidden" name="action1" value="1"> File 1: <input type="file" name="file1" size="30"><br> File 2: <input type="file" name="file2" size="30"><br> <br> <input type="submit" value="Upload"> </form> </font></p> </body> </html> <? } ?> <?php //计数器 //本计数器无需数据库支持。 //说明: // $five,$four等标量表示零的个数,放在数字前构成6位 //的来访者数目。当然,如果你的网站 //浏览量十分巨大,你可以添加$six,$seven等等构成更大的数字显 //示来访者的数目。 function Counter() { $five="00000"; $four="0000"; $three="000"; $two="00"; $one="0"; $counter="counternumber.dat"; //存放访客数目的文件.dat格式 if (!file_exists($counter)) //判断文件是否存在,如果不存在以写方式建立一个文件 { $counter=fopen($counter,"w"); fputs($counter,"0"); fclose($counter); } else { $num=file($counter,"r"); //如果文件存在则读出文件,并加1 $num[0]+=1; if($num[0]<10){ //判断数字的大小,如果小于100000根据不同情况在前面 print "$five"."$num[0]"; //加上不同个数的0,为了凑够6位。 }elseif($num[0]<100){ print "$four"."$num[0]"; }elseif($num[0]<1000){ print "$three"."$num[0]"; }elseif($num[0]<10000){ print "$two"."$num[0]"; }elseif($num[0]<100000){ print "$one"."$num[0]"; }else{ print "$num[0]"; } } $fp=fopen($counter,"w"); //以写入文件方式打开文件 fputs($fp,"$num[0]"); //将加过1的数字放入文件中 fclose($fp); //关闭文件 } ?> <!-- 可以用<?php Counter()?>形式调用函数,并用html标记或 CSS样式单来修饰显示出的数字,如下所示 --> <html> <body> <U> <B> <FONT SIZE="9" face="verdana" COLOR="#ffcc00"> <?php Counter()?> </FONT> </B> </U> </body> </html> <? highlight_file($filename); //高亮显示文件代码 ?> <body bgcolor="#fafad2"> <? require ("phplist.inc"); if ($rootpath=="") {$rootpath=$htmlroot;} function filelist($pathname){ //遍历所有的文件和目录,$pathnam为起始目录,$searchs为搜索关键字 global $htmlroot; if (eregi("[/][.][.]$",$pathname)) { $temp=split("[/]",$pathname); $pathname=""; for ($tt=1;$tt<(count($temp)-2);$tt++) $pathname=$pathname."/".$temp[$tt]; } echo $pathname."<br>"; $handle=opendir($pathname); //打开目录 if (@chdir($pathname)) { //cd 进入目录,若无权限则不进入 $file = readdir($handle); //读出所有当前目录下的元素名,第一次读出为‘。’,指上层目录 while ($file = readdir($handle)) { //若有元素就进行以下处理 $fname=$pathname."/".$file; //将元素名与当前目录名结合组成完整的文件名,并赋值给$fname if ((is_file($file)) and (ereg("\.php[3]{0,1}$",$file) or ereg("\.htm[l]{0,1}$",$file))) //判断是否为文件并且是否以.php和.php3结尾 { $temppp=split($htmlroot,$fname); echo "<a href=$temppp[1]>".$file."</a> ".filesize($file)."bytes <a href=codeshow.php?filename=$fname><font size=-1>源文件</font></a><br>"; //findinfile($fname,$searchs); //调用findinfile函数 } elseif (is_dir($fname)) { //判断是否为目录 linkres($fname); //filelist($fname,$searchs);} //递归调用filelist函数 } } chdir(".."); //结束当前递归,返回上层 } closedir($handle); //关闭当前目录读取 } // function linkres($filename){ $tpath=split("/web/html",$filename); $turepath=$tpath[1]; ereg("[^\\\/\~]{0,}$",$filename,$res); //< |
请发表评论