欧美日韩精品在线,国内精品久久久久久久久,一级毛片恃级毛片直播,清纯唯美亚洲综合欧美色

PHP 驗證碼 詳細(xì)代碼帶注釋 推薦!_PHP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:PHP操作文件類實例代碼
發(fā)一個剛寫完的文件操作類 第一次寫類,寫的不好,大家多提意見,不過不要罵我 剛才又加了兩個功能,又加了注釋,高手一定幫我看看哪有問題啊,謝謝 file.class.php ?php /** *本類為文件操作類,實現(xiàn)了文件的建立,寫入,刪除,修改,復(fù)制,移動,創(chuàng)建目錄,

checkcode.php

生成驗證碼圖片,還有變量 $_SESSION[check_pic]。

  1. <? 
  2.  
  3. session_start(); 
  4.  
  5. for($i=0; $i<4; $i++){ 
  6.     $rand.= dechex(rand(1,15)); 
  7. $_SESSION[check_pic]=$rand
  8. //echo $_SESSION[check_pic]; 
  9. // 設(shè)置圖片大小 
  10. $im = imagecreatetruecolor(100,30); 
  11. // 設(shè)置顏色 
  12. $bg=imagecolorallocate($im,0,0,0); 
  13. $te=imagecolorallocate($im,255,255,255); 
  14. // 把字符串寫在圖像左上角 
  15. imagestring($im,rand(5,6),rand(25,30),5,$rand,$te); 
  16. // 輸出圖像 
  17. header("Content-type:image/jpeg"); 
  18. imagejpeg($im); 
  19.  
  20. ?> 
form.php
通過 <img src="checkcode.php"> 調(diào)用生成的驗證碼圖片
  1. <div class="bottomAds"> 
  2. <fieldset class="bottomAds_quote"><legend>留言</legend> 
  3. <div class="ads"> 
  4. <form action="../utity/post.php" method="post" onsubmit="return chkinput(this)"> 
  5. <input name="name" type="text" /> 您的名字 
  6. <input name="email" type="text" /> 您的郵件 
  7. <input name="website" type="text" /> 您的網(wǎng)站 
  8. <textarea name="content" style="width:340; height:150;"> 
  9. </textarea><br /> 
  10. <img src="checkcode.php"><input type="text" name="check"><br /> 
  11. <input type="submit" value="提交" /> 
  12. </form> 
  13. </div> 
  14.  
  15. <br clear="both" />  
  16. </fieldset> 
imagestring($im,rand(5,6),rand(25,30),5,$rand,$te); 使用了 int imagestring(int im, int font, int x, int y, string s, int col); 函數(shù),這個函數(shù)用于繪橫式字符串。
這個函數(shù)在圖片上繪出水平的橫式字符串。參數(shù) font 為字形,設(shè)為 1 到 5 表示使用默認(rèn)字形。參數(shù) x、y 為字符串起點坐標(biāo)。字符串的內(nèi)容放在參數(shù) s 上。參數(shù) col 表示字符串的顏色。
post.php
比較 $_POST[check] 與 $_SESSION[check_pic],若相等則執(zhí)行數(shù)據(jù)庫插入操作。不相等就返回上一頁。
  1. <?php 
  2.  
  3.     session_start(); 
  4.  
  5.     if(isset($_POST[check])) 
  6.     { 
  7.         if($_POST[check] == $_SESSION[check_pic]) 
  8.         { 
  9.             // echo "驗證碼正確".$_SESSION[check_pic]; 
  10.             require("dbinfo.php"); 
  11.             $name = $_POST['name']; 
  12.             $email = $_POST['email']; 
  13.             $website = $_POST['website']; 
  14.             $content = $_POST['content']; 
  15.             $date = date("Y-m-d h:m:s"); 
  16.      
  17.             // 連接到 MySQL 服務(wù)器 
  18.             $connection = mysql_connect ($host$username$password); 
  19.             if (!$connection)  
  20.             { 
  21.                 die('Not connected : ' . mysql_error()); 
  22.             } 
  23.      
  24.             // 設(shè)置活動的 MySQL 數(shù)據(jù)庫 
  25.             $db_selected = mysql_select_db($database$connection); 
  26.             if (!$db_selected)  
  27.             { 
  28.                 die ('Can\'t use db : ' . mysql_error()); 
  29.             } 
  30.      
  31.             // 向數(shù)據(jù)庫插入數(shù)據(jù) 
  32.             $query = "insert into table (nowamagic_name, nowamagic_email, nowamagic_website, nowamagic_content, nowamagic_date) values ('$name','$email','$website','$content','$date')";  
  33.      
  34.             $result = mysql_query($query); 
  35.             if($result
  36.             { 
  37.                 echo "<script>alert('提交成功'); history.go(-1);</script>"
  38.             } 
  39.             if (!$result)  
  40.             { 
  41.                 die('Invalid query: ' . mysql_error()); 
  42.             } 
  43.         } 
  44.         else 
  45.         { 
  46.             echo "<script>alert('驗證碼錯誤'); history.go(-1);</script>"
  47.         } 
  48.     } 
  49.       
  50. ?> 

分享:PHP上傳自動生成縮略圖及水印類(含代碼)
思路很大一部分是原創(chuàng)的,但也有一些是COPY網(wǎng)絡(luò)的,寫得不夠規(guī)范,還請各位大大不要見笑,同時給小弟些意見。 開始第一步: 創(chuàng)建文件夾,布局: annex:附件(該目錄下存放上傳的原圖片) |— smallimg:存放縮略圖片 |— mark:存放水印圖片 include:存放

來源:模板無憂//所屬分類:PHP教程/更新時間:2012-06-10
相關(guān)PHP教程