Php instance verification code and login instance-PHP source code

Source: Internet
Author: User
Ec (2); php instance verification code and login instance & lt ;? Phpsession_start (); if ($ act & quot; init & quot;) {& nbsp; Header (& quot; Content-type: imagepng & quot;); & nbsp; srand (microtime () * 100000); & nbsp; $ login_check_number script ec (2); script

Php instance verification code and login instance

Session_start ();

If ($ act = "init ")
{
Header ("Content-type: image/png ");
Srand (microtime () * 100000 );
$ Login_check_number = strval (rand ("1111", "9999 "));

Session_register ("login_check_number ");
// The SESSION is used to save the verification code.
// You can also use cookies.
// Setcookie ("login_check_number", $ login_check_number );
// Delete session_start () in the first line;
// COOKIE is not recommended because it cannot be used for security verification.

$ H_img = imagecreate (40, 17 );
$ C_black = ImageColorAllocate ($ h_img, 0, 0 );
$ C_white = ImageColorAllocate ($ h_img, 255,255,255 );
Imageline ($ h_img, 1, 1,350, 25, $ c_black );
Imagearc ($ h_img, 200, 15, 20, 20, 35,190, $ c_white );
Imagestring ($ h_img, 5, 2, 1, $ login_check_number, $ c_white );
ImagePng ($ h_img );
ImageDestroy ($ h_img );

Die ();
}
/*
Usage:
Add

Add the following code to the login verification PHP page (Note: No output is allowed before the code is added because SESSION is used)

// $ Number indicates the value of the verification code you entered.

Include_once ("./checkNumber. php ");

// Check the verification code

If ($ number! = $ Login_check_number | empty ($ number ))
{
Print ("Incorrect verification code! ");
Die ();
}
*/
?>
A very comprehensive php Technology website, php enthusiasts have a wealth of articles and source code.
SESSION usage problems:
If the logon page is opened and the logon fails after the SESSION expires, the logon fails.
COOKIE usage problems:
The COOKIE is stored on the client, so it is better not to use the COOKIE.

For the VBB Forum, save checkNumber. php and modify the template content of the MYSQL database template data table titled logincode forumhome_logincode username_loggedout.
Then in the member. php
If ($ action = "login ")
Add later

// Check the verification code
Include_once ("./checkNumber. php ");
If ($ number! = $ Login_check_number | $ number = "")
{
Print ("Incorrect verification code! ");
Die ();
}

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.