php添加驗證碼

來源:互聯網
上載者:User
一個註冊的php網站怎麼加一段驗證碼呢?
求大神指教
最簡單的四個數字那種就行
線上等啊!!!


回複討論(解決方案)

//---------驗證碼產生函數-------//public function verify_image(){//產生驗證碼圖片header("Content-type: image/png");// 全數字$str = "2,3,4,5,6,7,8,9,a,b,c,d,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z"; //要顯示的字元,可自己進行增刪$list = explode(",", $str);$cmax = count($list) - 1;$verifyCode = '';for ( $i=0; $i < 5; $i++ ){$randnum = mt_rand(0, $cmax);$verifyCode .= $list[$randnum]; //取出字元,組合成為我們要的驗證碼字元}//$_SESSION['code'] = $verifyCode;        //將字元放入SESSION中//$this->session->set_userdata('code', $verifyCode);$im = imagecreate(58,28);    //產生圖片$black = imagecolorallocate($im, 0,0,0);     //此條及以下三條為設定的顏色$white = imagecolorallocate($im, 255,255,255);$gray = imagecolorallocate($im, 200,200,200);$red = imagecolorallocate($im, 255, 0, 0);imagefill($im,0,0,$white);     //給圖片填充顏色//將驗證碼繪入圖片imagestring($im, 5, 10, 8, $verifyCode, $black);    //將驗證碼寫入到圖片中for($i=0;$i<50;$i++){imagesetpixel($im, rand(0,58) , rand(0,28) , $black);    //加入點狀幹擾素    imagesetpixel($im,rand(0,58),rand(0,28),$red);    imagesetpixel($im, rand(0,58) , rand(0,28) , $gray);    //imagearc($im, rand(0,58), rand(0,28), 20, 20, 75, 170, $black);    //加入弧線狀幹擾素    //imageline($im, rand(0,58), rand(0,28), rand(0,58), rand(0,28), $red);    //加入線條狀幹擾素}imagepng($im);imagedestroy($im);}

請問這個是另外單開一個檔案還是直接加在原來的上面呢

---------------------------------------------------------------------------

session_start();
include("Config/Config.php");
include("ip.php");
if(!$isREG) die("帳號註冊功能已關閉,請等待開放再註冊!");
if($_POST){
//提交
include_once("Config/function_common.php");
$illegal=illegalsubmit();
if(!$illegal) die("禁止非法提交");
$POST=Addslashess($_POST);

include_once("Config/mysql_new_class.php");
$con=new mysql_class($SQLhost,$SQLuser,$SQLPWD,$DATABASE);

//帳號是否存在
$sql="select username,password from oluc_user where username='$POST[username]'";
$usr=$con->queryrow($sql);

$i = $POST['ip'];
$pass1 = rawurlencode(base64_encode($POST['password']));
$pass2 = rawurlencode(base64_encode($POST['repassword']));
if($pass1!=$pass2){
die("");
}else{
if(!$usr)
{
$sql="insert into oluc_user(UserName,PassWord,CreateTime,CreateIp) values('$POST[username]','$POST[password]',now(),'$i')";
mysql_query($sql);
$username=rawurlencode(base64_encode($POST[username]));
$password=rawurlencode(base64_encode($POST[password]));
//$url ='login.php';
//header("Location: $url");
//exit;
die("");
}else{ die("");}
}
mysql_close();
}
?>




<?php echo $Title ?>修改密碼






進入官網快速儲值" target="_blank">官方論壇" onclick="window.external.addFavorite(location.href,'');return false;" rel="sidebar" title="">收藏本頁














----------------------------------------------------------

我的是這樣的 求教!!!

驗證碼:
function create_code(){

document.getElementById('code2').src = 'verify_image';
}

大神能否直接加到我發的那裡面
完全不懂這些東西
麻煩了


感謝感謝萬分感謝!!!

你的驗證碼在哪就放哪啊



完全沒搞懂 呵呵

$code = mt_rand(1000,9999);$_SESSION['code' ] = $code;



echo $_SESSSION['code'];

看下 gd2 自己畫個吧。

其實可以自己去極驗驗證的後台下載一個他們的SDK,直接安裝好就可以使用啦,很方便的還可以查看後台資料。關鍵是安全性很高哦,還不用自己編程,滑動一下就搞定了。http://www.geetest.com/

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.