PHP JS CSS Session Implementation Verification code function

Source: Internet
Author: User

PHP JS CSS Session Implementation Verification code function

Page
<?php
Verification Code
if (Isset ($_post["Authcode")) {
Session_Start ();

    if (strtolower($_POST["authcode"]) == $_SESSION["authcode"]) {        echo "<font color=‘#0000cc‘>输入正确</font>";    } else {        echo "<font color=‘#cc0000‘>输入错误</font>";    }    exit();}

?>

<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> Confirm Verification Code </title>
<script type= "Text/javascript" ></script>
<body>
<form action= "test.php" method= "POST" >
<p> captcha Image: "width=" 100px "height=" </p>
<a href= "javascript:void (0)" onclick= "document.getElementById (' captcha_img '). src= ' 1.php?r= ' +Math.random ()" > Change one? </a>
<p> Please enter the contents of the Picture: <input type= "text" name= "Authcode" value= "/></p>
<p><input type= "Submit" value= "commit" style= "padding:6px 20px";></p>
</form>
</body>

Back-end PHP processing generate verification Code
<?php

Session_Start ();

Header ("Content-type:image/png");

Generate white Basemap $image = imagecreatetruecolor (0); $bgcolor = Imagecolorallocate ($image, 255, 255, 255); Imagefill ($image    , 0, $bgcolor);//Generate 4 colored random characters/*1 on a white basemap. Generate 4 digits for ($i =0; $i <4; $i + +) {$fontsize = 6;    $fontcolor = Imagecolorallocate ($image, rand (0, +), rand (0, +), 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);}    *///2. Generate random alphanumeric $captch_code = "";//The generated verification code is stored in the variable for ($i =0; $i <4; $i + +) {$fontsize = 6;    $fontcolor = Imagecolorallocate ($image, rand (0, +), rand (0, +), rand (0, 120));    Random interception of alphanumeric $data = "abcdefghijkmnopqrstuvwxyz23456789";    $fontcontent = substr ($data, Rand (0,strlen ($DATA)), 1);    $captch _code.= $fontcontent;//Append to verification code to store $x = ($i *100/4) + rand (5, 10);    $y = rand (5, 10); Imagestring ($image, $fontsize, $x, $y, $fontcontent, $fontcolor);} $_session["Authcode"] = $captch _code;//Save to SESSION//generate random points on white basemap (interference Element) for ($i =0; $i <200; $i + +){$pointcolor = Imagecolorallocate ($image, Rand (), Rand (50, 200)); Imagesetpixel ($image, rand (1, $), rand (1,), $pointcolor);} Generates a random line (interference element) for ($i =0; $i <3; $i + +) on a white basemap {$linecolor = Imagecolorallocate ($image, Rand (UP), Rand), Rand (    80, 220)); Imageline ($image, rand (1), Rand (1, $), rand (1,), rand (1), $linecolor);} Imagepng ($image); Imagedestroy ($image);

?> "

PHP JS CSS Session Implementation Verification code function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.