亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

PHP實現驗證碼制作

難度初級
時長 1小時20分
學習人數
綜合評分9.80
173人評價 查看評價
10.0 內容實用
9.8 簡潔易懂
9.6 邏輯清晰
  • http://img1.sycdn.imooc.com//645fa0e200018a3308280372.jpg

    隨即中文驗證碼

    查看全部
  • 動態校驗

    http://img1.sycdn.imooc.com//645f9f7a0001d00d07870156.jpg

    查看全部
  • 實現字母和數字混合驗證碼

    for 循環,字典由字母與數字組成。

    http://img1.sycdn.imooc.com//645f9be00001df7707120289.jpg

    查看全部
  • imagesetpixel畫一個隨機的像素。

    imagesetpixel(resource $iamge,int $x,int $y,int color)

    imageline(resource $image,int $x1,int $y1,int $x2,int $y2,int $color)畫一條線端。

    查看全部
  • 實現數字驗證碼

    在底圖上顯示隨機數字

    for循環

    變色驗證碼

    隨機的點——干擾元素



    實現數字驗證碼

    在底圖上顯示隨機數字

    for循環

    變色驗證碼

    隨機的點——干擾元素

    查看全部
  • 搭建php運行環境,搜索XAMPP下載安裝。

    打開xampp文件地址,在站點文件夾htdots下,新建一個php文件。輸入簡單的內容判斷是否能正常運行。

    檢查php是否支持GD,輸入<?php? phpinfo():查看輸出即可。

    實現簡單的驗證碼

    在htdots站點下,打開project目錄創建php文件;

    生成底圖:圖像繪制imagecreatetruecolor(int $width,int $height) 。

    header方法輸出圖片的類型;

    imagecreatetruecolor(int $width,int $height) 。默認返回黑色底圖。

    imagecolorallocate($image,int red,int green,int blue)為圖像分配顏色。

    9.imagefill($image,int x,int y,int color)區域填充,在iamge圖像的坐標x,y(圖像左上角為(0,0)處用color顏色執行區域填充;

    查看全部
  • <?php

    //phpinfo();

    //生成驗證碼底圖

    $image=@imagecreatetruecolor(100, 30);//返回一個黑色的圖片

    $text_color = imagecolorallocate($image, 255, 255, 255);

    // $bgcolor=imagecolorallocate($image,255,255,255);

    // imagefill($image,0,0,$bgcolor);

    // header('content-type: image/png');

    // imagedestroy($image);

    imagefill($image,0,0,$text_color);//區域填充

    for($i=0;$i<4;$i++)//利用for循環生成四位數字

    {

    ? ? $fontsize=6;//字體大小

    ? ? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//設置數字的顏色

    ? ? $fontcontent=rand(0,9);

    ? ? //注意事項:控制好字體的大小和分布,避免字體重疊或顯示不全

    ? ? $x=($i*100/4)+rand(5,10);

    ? ? $y=rand(5,10);

    ? ? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);

    }

    for($i=0;$i<200;$i++)

    {

    ? ? $pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));

    ? ? //生成隨機點干擾顏色(較淺),給惡意破解程序增加難度

    ? ? imagesetpixel($image,rand(1,99),rand(1,99),$pointcolor);

    }

    header ('Content-Type: image/png');

    imagepng($image);

    imagedestroy($image);

    查看全部
  • <?php

    //phpinfo();

    //生成驗證碼底圖

    $image=@imagecreatetruecolor(120, 20);//返回一個黑色的圖片

    $text_color = imagecolorallocate($image, 255, 255, 255);

    // $bgcolor=imagecolorallocate($image,255,255,255);

    // imagefill($image,0,0,$bgcolor);

    // header('content-type: image/png');

    // imagedestroy($image);

    imagefill($image,0,0,$text_color);//區域填充


    header ('Content-Type: image/png');

    imagepng($image);

    imagedestroy($image);

    查看全部
  • 文字無法顯示

    查看全部
  • 輸出一個隨機數。 有的瀏覽器會對相同url做cache,若cache了,這個請求就達不到我們效果。所以加個隨機數,避免被瀏覽器cache。


    有的瀏覽器不夠聰明,會cache歷史數據,導致刷新失敗。 加隨機數是這個作用。

    查看全部
  • http://www.xianlaiwan.cn/qadetail/25142

    查看全部
  • https://bbs.csdn.net/topics/390932524

    為什么驗證碼 必須要開啟 ob_clean 才可以顯示?

    這表示你的程序前面有輸出,<?php?前有空格、空行、文件有BOM頭

    查看全部
  • 啦啦啦啦
    查看全部
    0 采集 收起 來源:驗證碼介紹

    2019-03-20

  • SESSION 存儲驗證信息

    查看全部
  • 實現簡單的驗證碼


    查看全部
  • captcha.php

    <?php

    session_start();


    //畫布

    $image = imagecreatetruecolor(100, 30);

    $bgcolor = imagecolorallocate($image, 255, 255, 255);

    imagefill($image, 0, 0, $bgcolor);


    //隨機數字

    /*

    for ($i=0; $i < 4; $i++) {

    $fontsize = 10;

    $fontcolor = imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));

    $fontcontent = rand(0,9);


    $x = ($i*100/4) + rand(5,10);

    $y = rand(5,10);


    imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);

    }

    */


    $captch_code = '';

    //數字字母組合

    for ($i=0; $i <4; $i++) {

    $fontsize = 8;

    $fontcolor = imagecolorallocate($image, rand(0,80), rand(0,80), rand(0,80));


    $data = 'abcdefghijkmnpqrstuvwxy3456789';

    $fontcontent = substr($data, rand(0,strlen($data)),1);

    $captch_code .= $fontcontent;


    $x = ($i*100/4) + rand(5,10);

    $y = rand(5,10);


    imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);


    }

    $_SESSION['authcode'] = $captch_code;

    //將captch_code保存到session的authcode中


    //干擾點

    for ($i=0; $i <300 ; $i++) {

    $pointcolor = imagecolorallocate($image, rand(80,220), rand(80,220), rand(80,220));

    imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor);

    }

    //干擾線

    for ($i=0; $i <3 ; $i++) {

    $linecolor = imagecolorallocate($image, rand(120,220), rand(120,220), rand(120,220));

    imageline($image, rand(1,99), rand(1,29), rand(1,99), rand(1,29), $linecolor);

    # code...

    }


    header('content-type: image/png');

    imagepng( $image );


    //end

    imagedestroy( $image );


    ?>


    查看全部
  • form.php

    <?php

    header('content-type:text/html;charset=utf-8');

    if(isset($_REQUEST['authcode'])){

    session_start();

    if(strtolower($_REQUEST['authcode'])==$_SESSION['authcode']){

    echo '<font color="#0000CC">輸入正確</font>';

    }else{

    echo '<font color="#CC0000"> <b>輸入錯誤</b> </font>';

    }

    exit();

    }

    ?>


    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="utf-8" />

    <title>確認驗證碼</title>

    </head>

    <body>

    <form method="post" action="./form.php">

    <p>驗證碼圖片:<img id="captcha_img" border="1" src="./captcha.php?r=<?php echo rand();?>" width:100px; height:30px" />

    <a href="javascript:void(0)" onclick="document.getElementById('captcha_img').src='./captcha.php?r='+Math.random()">換一個?</a>

    <p>請輸入圖片中的內容:<input type="text" name="authcode" value="" /></p>

    <p><input type="submit" value="提交" ></p>

    </form>

    </body>

    </html>


    查看全部
  • 驗證碼
    查看全部
    0 采集 收起 來源:驗證碼介紹

    2018-06-16

  • “寫請求的消耗遠大于讀請求”

    查看全部
    0 采集 收起 來源:驗證碼介紹

    2018-05-11

  • <?php

    session_start();

    $captcha_code='';

    for($i=0;$i<4;$i++){

    $data='abcdefghigkmnpqrstuvwxy13456789';

    $fontcontent=substr($data,rand(0,strlen($data)-1),1);

    ? ? ? ??

    $captcha_code.=$fontcontent;

    }

    $_SESSION['authcode']=$captcha_code;

    echo $_SESSION['authcode'];

    //證明session是開著的


    /* ?$str = '1';

    $str .= '2';

    $str .= '3';

    $str .='4';

    echo $str; 拼接規則的實驗*/


    ?>?


    查看全部
首頁上一頁1234567下一頁尾頁

舉報

0/150
提交
取消
課程須知
本課程適合PHP初學者或者自學的童鞋們。
老師告訴你能學到什么?
1、如何拆解驗證碼項目 2、PHP的繪圖擴展GD庫的使用 3、如何用GD函數畫圖與驗證碼內容 4、如何用PHP做驗證碼校驗,及動態校驗 5、怎么實現中文、圖片、視頻驗證碼

微信掃碼,參與3人拼團

微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復購買,感謝您對慕課網的支持!