PHP Verification code is out of sync with the session

Source: Internet
Author: User
Tags set background
This post was last edited by mclubing on 2012-06-14 16:13:53

 
  


Here is the front-end code
 
  
 
  

Global Pass Club

Backstage of global Club clubhouse


Reply to discussion (solution)

Really interesting, the landlord of this brain to get around the confused.

What do you want to do on this page?

The verification code picture has to do the session, submits the form the page to use the session, you put a session in this page is wants to prove you a brain paste.

Regardless of the landlord want to have what needs it, first look at the problem

while (($authnum =rand ()%100000) <10000);
$_session[' Authnum ']= $authnum;
This means that the assignment of the session variable is conditional, and when the random number you produce does not satisfy the condition, the authnum is saved last time, but the subsequent code is still output, so the output is definitely not synchronized.

PHP Code


Session_Start ();//storing random numbers in session
Srand (Double) microtime () *1000000);//sow a seed that generates random numbers to facilitate the use of random number generation below
$im = Imagecreate (62,20); Make picture background size
$black = Imagecoloralloca ...

Run a succession of questions. Each refresh takes the last time $authnum to figure it out.

It's a lot of mixed. Individual is the serious answer.

Understand the landlord's meaning.

  the landlord is not understood as  This TD first executes, then certainly the session also changed. Then  
 
   //The above session must also be TD session//------------------------------------------------------//Actually you can do a test, According to your understanding, TD above the Echo session and the following ECHO session is definitely not the same//then you put one on the TD, see if they are inconsistent.
 
  

Understand the landlord's meaning. PHP Code

The landlord is not understood as
OK, I'll try.

Reference to the 5 floor of the reply:

Understand the landlord's meaning. PHP Code

The landlord is not understood as
Still the same.

Front-end Code
Session_Start ();//Get Session variable Value
....
echo $_session[' Authnum '];//here is the output from the above
This work is done when the entire front-end code has not reached the browser
and

The checkcode.php is accessed when the browser reads the picture.
Obviously, the session data generated in the checkcode.php is later than the one you displayed on the page.

Front-end Code
Session_Start ();//Get Session variable Value
....
echo $_session[' Authnum '];//here is the output from the above
This work is done when the entire front-end code has not reached the browser
and
How to solve?

I have also touched this problem, and later resolved, but do not remember where the change.

Generate verification Code yzm.php

!--? php

//Generate CAPTCHA Picture
Session_Start ();
Header ("Content-type:image/gif");
Srand (Double) microtime () *1000000);
$im = imagecreate (50,25);//Set the width and height of the picture
$black = Imagecolorallocate ($im, 0,0,0);//Set background color
$white = Imagecolorall Ocate ($im, 255,255,255);//Set text color
$gray = imagecolorallocate ($im, 200,200,200);//Interference color
Imagefill ($im, 50,25,$ Gray);
while ($chk _num=rand ()%10000) <1000);
$_session["chk_num"] = $chk _num;

//Draws a four-bit integer verification code into the picture
Imagestring ($im, 5, 1, $chk _num, $white);//5, 5, 1 are indicated as font size, left margin, top margin
for ($i =0; $i < $i + +)//Add interfering pixel
{
Imagesetpixel ($im, Rand ()%70, Rand ()%30, $gray);
}
Imagepng ($im);
Imagedestroy ($im);

?>

Front


Verification Code judgment







Landlord can control, look down Where is the problem

Should be to get the correct verification code when submitting the form

Should be to get the correct verification code when submitting the form
I already know the wrong, but I do not know how to solve, the reason for the error is because browser loaded the HTML code before loading, and then load the picture, so there will be a slow picture of the reason, because the picture is loaded after the session.

Reference to the 11 floor of the reply:

Should be to get the correct verification code when submitting the form

I already know the wrong, but I do not know how to solve, the reason for the error is because browser loaded the HTML code before loading, and then load the picture, so there will be a slow picture of the reason, because the picture is loaded after the session.

Why do you need to know the information about the current picture? You do the verification code should be verified input verification code and the picture is consistent, as long as the submission of the form can be judged, you are not the demand?

Mark looks at work tomorrow.

Reference to the 14 floor of the reply:

Reference to the 11 floor of the reply:

Should be to get the correct verification code when submitting the form

I already know the wrong, but I do not know how to solve, the reason for the error is because browser loaded the HTML code before loading, and then load the picture, so there will be a slow picture of the reason, because the picture is loaded after the session.


Why do you need to know the information about the current picture? You should verify that the verification code entered is consistent with the image, as long as the form is submitted ...
Front desk Ajax

is a slow shot, is wrong, if the verification code in the HTML page reference, and at this time with PHP output, then the page is faster than the PHP output, which is wrong,
if ($_server["request_method"] = = "POST")
{

echo "submitted to Server". $_session["Verifycode"]. " This is filled in ". $_post[" GetCode "];
}
This synchronizes, is the HTML verification Code, and the post-postback session is the same. Verify that the two are equal.

And a similar problem has been encountered,

Submit the form validation information to another page for validation. Do not proceed on this page.

  • 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.