PHP Add Verification Code

Source: Internet
Author: User
Tags php website
How to add a verification code to a registered PHP website?
Ask the Great God for advice
The simplest four numbers, that's all.
Online wait Ah!!!


Reply to discussion (solution)

---------captcha generator-------//public function verify_image () {//Generate Captcha Picture header ("content-type:image/png");//full digit $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 "; To display the characters, you can make additions and deletions $list = explode (",", $str); $cmax = count ($list)-1; $verifyCode = "; for ($i =0; $i < 5; $i + +) {$randnu m = Mt_rand (0, $cmax); $verifyCode. = $list [$randnum];        Remove the characters, the combination becomes the captcha character we want}//$_session[' code ' = $verifyCode;    Put characters in session//$this->session->set_userdata (' Code ', $verifyCode); $im = Imagecreate (58,28);     Generate Picture $black = Imagecolorallocate ($im, 0,0,0); This bar and the following three are set for the color $white = Imagecolorallocate ($im, 255,255,255); $gray = Imagecolorallocate ($im, 200,200,200); $red =     Imagecolorallocate ($im, 255, 0, 0); Imagefill ($im, 0,0, $white);    Fill the picture with color//Draw the captcha into the picture imagestring ($im, 5, 8, $verifyCode, $black);    Write the captcha to the picture for ($i =0; $i <50; $i + +) {Imagesetpixel ($im, Rand (0,58), Rand (0,28), $black);    Added dot-like interferon 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), (a), (a), (a), $black);    Added arc-shaped interferon//imageline ($im, Rand (0,58), Rand (0,28), Rand (0,58), Rand (0,28), $red); Added line-like interferon}imagepng ($im); Imagedestroy ($im);}

Will this be another single file or directly add to the original?

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

Session_Start ();
Include ("config/config.php");
Include ("ip.php");
if (! $isREG) Die ("The account registration function is turned off, please wait for open re-registration!");
if ($_post) {
Submit
Include_once ("config/function_common.php");
$illegal =illegalsubmit ();
if (! $illegal) Die ("Prohibit unlawful submission");
$POST =addslashess ($_post);

Include_once ("config/mysql_new_class.php");
$con =new Mysql_class ($SQLhost, $SQLuser, $SQLPWD, $DATABASE);

Whether the account exists
$sql = "Select Username,password from Oluc_user where username= ' $POST [username] '";
$USR = $con->queryrow ($sql);

$i = $POST [' IP '];
$pass 1 = Rawurlencode (Base64_encode ($POST [' Password ']);
$pass 2 = Rawurlencode (Base64_encode ($POST [' Repassword ']);
if ($pass 1!= $pass 2) {
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 ();
}
?>




<title><?php echo $Title?> Change Password</title>






Enter the official website quick Recharge "target=" _blank ">" onclick= "Window.external.addFavorite (Location.href, ' '); return false; "rel=" sidebar "title=" "> Bookmark this page














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

Mine is this kind of advice!!!

Verification Code:
function Create_code () {

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

Can the great God be added directly to my hair?
I don't know anything about this.
It's trouble.


Thank you very much thank you!!!

Where do you put your verification code?



I don't understand it at all.

$code = Mt_rand (1000,9999); $_session[' code '] = $code;



echo $_sesssion[' code ';

Take a look at GD2 and draw it yourself.

In fact, you can go to the verification of the background to download a their SDK, direct installation can be used, it is convenient to view the background data. The key is the security is very high oh, do not have to do their own programming, swipe to get it done. http://www.geetest.com/

  • Related Article

    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.