PHP 驗證碼 詳細(xì)代碼帶注釋 推薦!_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:PHP操作文件類實例代碼發(fā)一個剛寫完的文件操作類 第一次寫類,寫的不好,大家多提意見,不過不要罵我 剛才又加了兩個功能,又加了注釋,高手一定幫我看看哪有問題啊,謝謝 file.class.php ?php /** *本類為文件操作類,實現(xiàn)了文件的建立,寫入,刪除,修改,復(fù)制,移動,創(chuàng)建目錄,
checkcode.php
生成驗證碼圖片,還有變量 $_SESSION[check_pic]。
form.php
- <?
- session_start();
- for($i=0; $i<4; $i++){
- $rand.= dechex(rand(1,15));
- }
- $_SESSION[check_pic]=$rand;
- //echo $_SESSION[check_pic];
- // 設(shè)置圖片大小
- $im = imagecreatetruecolor(100,30);
- // 設(shè)置顏色
- $bg=imagecolorallocate($im,0,0,0);
- $te=imagecolorallocate($im,255,255,255);
- // 把字符串寫在圖像左上角
- imagestring($im,rand(5,6),rand(25,30),5,$rand,$te);
- // 輸出圖像
- header("Content-type:image/jpeg");
- imagejpeg($im);
- ?>
通過 <img src="checkcode.php"> 調(diào)用生成的驗證碼圖片
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ù)用于繪橫式字符串。
- <div class="bottomAds">
- <fieldset class="bottomAds_quote"><legend>留言</legend>
- <div class="ads">
- <form action="../utity/post.php" method="post" onsubmit="return chkinput(this)">
- <input name="name" type="text" /> 您的名字
- <input name="email" type="text" /> 您的郵件
- <input name="website" type="text" /> 您的網(wǎng)站
- <textarea name="content" style="width:340; height:150;">
- </textarea><br />
- <img src="checkcode.php"><input type="text" name="check"><br />
- <input type="submit" value="提交" />
- </form>
- </div>
- <br clear="both" />
- </fieldset>
這個函數(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ù)庫插入操作。不相等就返回上一頁。
- <?php
- session_start();
- if(isset($_POST[check]))
- {
- if($_POST[check] == $_SESSION[check_pic])
- {
- // echo "驗證碼正確".$_SESSION[check_pic];
- require("dbinfo.php");
- $name = $_POST['name'];
- $email = $_POST['email'];
- $website = $_POST['website'];
- $content = $_POST['content'];
- $date = date("Y-m-d h:m:s");
- // 連接到 MySQL 服務(wù)器
- $connection = mysql_connect ($host, $username, $password);
- if (!$connection)
- {
- die('Not connected : ' . mysql_error());
- }
- // 設(shè)置活動的 MySQL 數(shù)據(jù)庫
- $db_selected = mysql_select_db($database, $connection);
- if (!$db_selected)
- {
- die ('Can\'t use db : ' . mysql_error());
- }
- // 向數(shù)據(jù)庫插入數(shù)據(jù)
- $query = "insert into table (nowamagic_name, nowamagic_email, nowamagic_website, nowamagic_content, nowamagic_date) values ('$name','$email','$website','$content','$date')";
- $result = mysql_query($query);
- if($result)
- {
- echo "<script>alert('提交成功'); history.go(-1);</script>";
- }
- if (!$result)
- {
- die('Invalid query: ' . mysql_error());
- }
- }
- else
- {
- echo "<script>alert('驗證碼錯誤'); history.go(-1);</script>";
- }
- }
- ?>
分享:PHP上傳自動生成縮略圖及水印類(含代碼)思路很大一部分是原創(chuàng)的,但也有一些是COPY網(wǎng)絡(luò)的,寫得不夠規(guī)范,還請各位大大不要見笑,同時給小弟些意見。 開始第一步: 創(chuàng)建文件夾,布局: annex:附件(該目錄下存放上傳的原圖片) |— smallimg:存放縮略圖片 |— mark:存放水印圖片 include:存放
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時間
- PHP中獎概率的抽獎算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運算符優(yōu)先級介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
- 教程說明:
PHP教程-PHP 驗證碼 詳細(xì)代碼帶注釋 推薦!。