For questions about the session verification code, refresh the verification code and keep the value of the session unchanged.

Source: Internet
Author: User
Session verification code problem, refresh the verification code, the value of the session remains unchanged, ask the high person to answer this post, and finally edit php for the verification code program at 2013-01-1411: 18: 32, after changing the server, refresh the verification code. the verification code has changed, but the s session verification code is incorrect. refresh the verification code. The value of the session remains unchanged.
At the end of this post, yieri_z edited the php verification code program at 11:18:32 on. the verification code was refreshed after the server was changed. the verification code was changed, but the session was the first initial value, I suspect it's a server problem. do some people know what's going on?


The checkimage. php page of the verification code is as follows:
Header ("Content-type: image/gif ");

$ Border = 0; // whether the border is required; 1: 0: not required
$ How = 4; // Number of digits of the verification code
$ W = $ how * 15; // image width
$ H = 25; // Image height
$ Fontsize = 5; // font size
$ Alpha = "ABCDEFGHIJKLMNPQRSTUVWXYZ"; // verification code content 1: letter
$ Number = "123456789"; // verification code content 2: number
$ Randcode = ""; // verification code string initialization
Srand (double) microtime () * 1000000); // initialize the random number seed

$ Im = ImageCreate ($ w, $ h); // Create a verification image

$ Bgcolor = ImageColorAllocate ($ im, 255,255,255); // you can specify the background color.
ImageFill ($ im, 0, 0, $ bgcolor); // fill the background color
If ($ border)
{
$ Black = ImageColorAllocate ($ im, 0, 0, 0); // you can specify the border color.
ImageRectangle ($ im, 0, 0, $ W-1, $ H-1, $ black); // draw a border
}

For ($ I = 0; $ I <$ how; $ I ++)
{
$ Alpha_or_number = mt_rand (0, 1); // letters or numbers
$ Str = $ alpha_or_number? $ Alpha: $ number;
$ Which = mt_rand (0, strlen ($ str)-1); // specify the character
$ Code = substr ($ str, $ which, 1); // Obtain the character
$ J =! $ I? 4: $ j + 15; // specifies the position of the painted character.
$ Color3 = ImageColorAllocate ($ im, mt_rand (0,100), mt_rand (0,100), mt_rand (0,100); // character color
ImageChar ($ im, $ fontsize, $ j, 3, $ code, $ color3); // draw characters
$ Randcode. = $ code; // add a verification code string to a bit by bit
}

For ($ I = 0; $ I <$ how * 20; $ I ++) // draws background interference points
{
$ Color2 = ImageColorAllocate ($ im, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255); // interference point color
ImageSetPixel ($ im, mt_rand (0, $ w), mt_rand (0, $ h), $ color2); // interference point
}

// Write the verification code string to the session
Session_start ();
$ _ SESSION ['randcode'] = $ randcode;

/* Drawing ends */
Imagegif ($ im );
ImageDestroy ($ im );
/* Drawing ends */


Registration page reg.html call code:
Verification code


Can't see clearly? Change Group


Php receiving page:
Header ("content-type: text/html; charset = utf-8 ");
Session_start ();

Echo "verification code session value:". $ _ SESSION ["randcode"];
Echo" ";
Echo "verification code submitted value:". $ reg_checkcode;


When you just run the reg.html page, for example, if the verification code is "A67E", click "cannot see clearly? After changing a group, the verification code is changed, but the value of $ _ SESSION ['randcode'] is still "A67E", no matter how many times I click "cannot see clearly? For another group, the verification code image is changed, but the session value is the initial value. what is the problem? Please help me. Session verification code
------ Solution --------------------
There is no good way to debug in one step.

Check whether the session directory is writable and whether the hard disk space is insufficient.
------ Solution --------------------
Set error_report and display_error of your php. ini file so that it can generate all the errors.
------ Solution --------------------
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.