Php: how can I add a verification code to a registered php website?
Please advise
The simplest four digits are enough.
Online !!!
Reply to discussion (solution)
// --------- Verification code generation function ------- // public function verify_image () {// Generate the verification code image header ("Content-type: image/png "); // Full number $ 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 "; // the character to be displayed, you can add or delete $ list = explode (",", $ str); $ cmax = count ($ list)-1; $ verifyCode = ''; for ($ I = 0; $ I <5; $ I ++) {$ randnum = mt_rand (0, $ cmax); $ verifyCode. = $ list [$ randnum]; // extract the characters and combine them into the verification code characters.} // $ _ SESSION ['code'] = $ verifyCode; // put the characters in the SESSION // $ this-> session-> set_userdata ('code', $ verifyCode); $ im = imagecreate (58,28 ); // generate an image $ black = imagecolorallocate ($ im, 255,255,255, 0); // set the color of this image and the following three items: $ white = imagecolorallocate ($ im ); $ gray = imagecolorallocate ($ im, 200,200,200); $ red = imagecolorallocate ($ im, 255, 0, 0); imagefill ($ im, $ white ); // fill in the image color // input the verification code into the image imagestring ($ im, 5, 10, 8, $ verifyCode, $ black ); // write the verification code to the image for ($ I = 0; $ I <50; $ I ++) {imagesetpixel ($ im, rand ), rand (), $ black); // add point interferon imagesetpixel ($ im, rand (), rand (), $ red); imagesetpixel ($ im, rand (75,170), rand (), $ gray); // imagearc ($ im, rand (), rand (), 20, 20, $ black); // add arc-like interferon // imageline ($ im, rand ), $ red); // add line-like interferon} imagepng ($ im); imagedestroy ($ im );}
Is this a separate file or is it directly added to the original file?
---------------------------------------------------------------------------
Session_start ();
Include ("Config/Config. php ");
Include ("ip. php ");
If (! $ IsREG) die ("The account registration function has been disabled. please wait for it to be opened before registration! ");
If ($ _ POST ){
// Submit
Include_once ("Config/function_common.php ");
$ Illegal = illegalsubmit ();
If (! $ Illegal) die ("illegal submission prohibited ");
$ 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'];
$ Pass1 = rawurlencode (base64_encode ($ POST ['password']);
$ Pass2 = rawurlencode (base64_encode ($ POST ['repassword']);
If ($ pass1! = $ Pass2 ){
Die ("script" alert ('Two passwords are different, please input them again '); history. back (); script ");
} 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 ("script" alert ('confirm account registration and transfer to login page'); location. href = 'login. php'; script ");
} Else {die ("script" alert ('Nickname is in use, please enter it again '); history. back (); script ");}
}
Mysql_close ();
}
?>
<? Php echo $ Title?> Change password
Go to the official website to quickly recharge "target =" _ blank "> Official Forum" onclick = "window. external. addFavorite (location. href ,' '); Return false; "rel =" sidebar "title =" "> Add this page to favorites