查看文件: index.php
大小: 7.15 KB
类型: application/octet-stream
<?php require_once('Connections/BE2.php'); ?> <? function getrandcode(){ $str =array(1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h'); $res=''; for($i=0;$i<4;$i++){ $rand=mt_rand(1,16); $res .=$str[$rand]; } return $res; } //if(isset($_POST['total']) && isset($_POST['count']) && $_POST['start']=='A'){ // update `dat1` set c3='Y' where 1 @session_start(); $security =false; // 是否是有效的執行 $mem=''; if(isset($_POST['start']) && $_POST['start']<>''){ $security = $_POST['privatetoken'] == $_SESSION['token']; if($security){ unset($_SESSION['token']); } if($security){ mysql_select_db($database_BE2, $BE2); $query_Rt2 = "SELECT * FROM dat1 WHERE 1"; //c3='N' $Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error()); $row_Rt2 = mysql_fetch_assoc($Rt2); $totalRows_Rt2 = mysql_num_rows($Rt2); $arr1=array(); do { $arr1['c0']=$row_Rt2['c2']; } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); $POST_total = $_POST['total']; $POST_count = $_POST['count']; $POST_except = $_POST['except']; $Rand = array(); //定義陣列 $count = $POST_count ; //共產生幾筆 if(isset($_POST['except'])){ /*文字轉陣列-排除名單*/ $Rand = explode(",",$POST_except); } while($count > 0){ $randval = mt_rand(1,$POST_total); //取亂數 if (!in_array($randval, $Rand)) { $count--; $Rand[] = $randval; //若無重復則 將亂數塞入陣列 // echo $randval.","; mysql_select_db($database_BE2, $BE2); $query_Rt2 = sprintf("SELECT * FROM dat1 WHERE c0='%s'",$randval); //c3='N' $Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error()); $row_Rt2 = mysql_fetch_assoc($Rt2); $totalRows_Rt2 = mysql_num_rows($Rt2); //echo $row_Rt2['c2']."<br>"; $mem="恭喜".$row_Rt2['c2']; mysql_select_db($database_BE2, $BE2); $query_Rt2 = sprintf("update dat1 set c3='N' WHERE c0='%s'",$randval); //c3='N' $Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error()); } } } } $token=md5(getrandcode()); $_SESSION['token'] = $token; mysql_select_db($database_BE2, $BE2); $query_Rt2 = "SELECT * FROM dat1 WHERE 1"; //c3='N' $Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error()); $row_Rt2 = mysql_fetch_assoc($Rt2); $totalRows_Rt2 = mysql_num_rows($Rt2); $rr=''; $arr1=array(); $n=0; $ff=0; if($totalRows_Rt2>0){ do { $arr1['c0']=$row_Rt2['c2']; if($row_Rt2['c3']=='N'){ $rr .=$row_Rt2['c0'].","; $ff++ ;} } while ($row_Rt2 = mysql_fetch_assoc($Rt2)); } $rr .= '0'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>立典抽獎</title> </head> <body> <form id="form1" name="form1" method="post" action=""> 剩餘獎數:<?= $totalRows_Rt2-$ff ?><br> <input type="hidden" name="total" id="total" value="<?= $totalRows_Rt2 ?>" readonly /> <input type="hidden" name="count" id="count" value="1" /> 姓名: <input name="except" type="hidden" id="except" value="<?= $rr ?>" /> <input name="start" type="text" id="start" value=""/> <input type="button" onclick="JsFunction();" value="送出" /> <input type="hidden" name="privatetoken" value="<?php echo $token;?>"> </form> <?= ($mem<>'')?$mem:"" ?> <hr> <script type="text/javascript"> function JsFunction() { form1.submit(); } </script> <?php mysql_free_result($Rt2); ?> <canvas id="fireworks" <? if($mem==''){?> style="display:none";<? }?>></canvas> <script> const canvas = document.getElementById('fireworks'); const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = 450;// //window.innerHeight; const fireworks = []; const particles = []; const hue = Math.random() * 360; function createFirework(x, y) { const firework = { x, y, vx: (Math.random() - 0.5) * 3, vy: Math.random() * -5 - 4, size: Math.random() * 3 + 2, color: 'hsl(' + hue + ', 100%, 50%)', particles: [], opacity: 1 }; fireworks.push(firework); } function createParticle(x, y, color) { const particle = { x, y, vx: (Math.random() - 0.5) * 2, vy: (Math.random() - 0.5) * 2, size: Math.random() * 2 + 1, color, opacity: 1 }; particles.push(particle); } function update() { ctx.clearRect(0, 0, canvas.width, canvas.height); for (const firework of fireworks) { ctx.beginPath(); ctx.fillStyle = firework.color; ctx.arc(firework.x, firework.y, firework.size, 0, Math.PI * 2); ctx.fill(); // 在烟花上显示文本 ctx.fillStyle = '#333'; // 设置文本颜色为白色 ctx.font = '60px Arial'; // 设置文本字体和大小 ctx.fillText('<?= $mem ; ?>', firework.x - 20, firework.y); // 显示文本 } for (let i = fireworks.length - 1; i >= 0; i--) { const firework = fireworks[i]; firework.x += firework.vx; firework.y += firework.vy; firework.vy += 0.1; firework.opacity -= 0.02; if (firework.opacity <= 0) { fireworks.splice(i, 1); for (let j = 0; j < 30; j++) { createParticle(firework.x, firework.y, firework.color); } } } for (let i = particles.length - 1; i >= 0; i--) { const particle = particles[i]; particle.x += particle.vx; particle.y += particle.vy; particle.vy += 0.05; particle.opacity -= 0.02; if (particle.opacity <= 0) { particles.splice(i, 1); } } while (fireworks.length < 5) { const x = Math.random() * canvas.width; createFirework(x, canvas.height); } for (const firework of fireworks) { ctx.beginPath(); ctx.fillStyle = firework.color; ctx.arc(firework.x, firework.y, firework.size, 0, Math.PI * 2); ctx.fill(); } for (const particle of particles) { ctx.beginPath(); ctx.fillStyle = particle.color; ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2); ctx.fill(); } requestAnimationFrame(update); } update(); setTimeout(() => { fireworks.length = 0; particles.length = 0; }, 5000); </script> </body> </html>
保存
取消
返回文件列表