The Captcha Class
創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的賓川網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!outputImage(); } function check($arr) { if (isset($arr) && is_array($arr)) { if (isset($arr[$this->sessionvar])) { if ($arr[$this->sessionvar] == $_SESSION[$this->sessionvar]) { return true; } } } } function randomString($length = 6) { $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; for ($i = 0; $i < $length; $i++) { $string .= $chars[mt_rand(0, strlen($chars)-1)]; } return $string; } function outputImage() { $this->img = ImageCreate ($this->width, $this->height); if ($this->img) { header("Content-type: p_w_picpath/png"); $bg = ImageColorAllocate($this->img, 255, 255, 255); $txt = ImageColorAllocate($this->img, 0, 0, 0); $string = $this->randomString($this->chars); ImageString($this->img, 31, $this->fontsize, 0, $string, $txt); Imagepng($this->img); $_SESSION[$this->sessionvar] = $string; } } } ?>
The class has two main functions, run() and check() – The run function will output an p_w_picpath so make sure the HTML p_w_picpath tag is linked to the file where you use the run() function. Examples below.
Showing the Image
include('captcha.php'); $captcha = new Captcha; $captcha->run();
If you name that file cp_w_picpath.php you can embed it into forms in the following way:
Checking the code
Wherever your form is submitting to is where you should be checking the code. This can either be in the same file or an external file. The following code will allow you to check the $_POST array and make sure the user has entered the correct code.
include('captcha.php'); $captcha = new Captcha; if ($captcha->check($_POST)) { echo 'Correct Code'; } else { echo 'Invalid Code'; }
生成圖
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。