The verification code is always missing. As a result, it is okay to make sure that the session_id cannot be correctly determined by other users' browsers, that is, my machine is faulty. Later, I changed the host, and the new system encountered a problem and crashed. Why? Php generates the verification code myauth. phpPHPcodeclassauth {about the verification code
Always get the unobtained value.
As a result, session_id cannot be correctly determined.
Other people's browsers are okay, that is, my machine is faulty.
Later, I changed the host, and the new system encountered a problem and crashed.
Why?
Php generates the verification code myauth. php
PHP code
Class auth {public function auth () {session_start (); // Start session $ str = "abcdefghijkmnpqrstuvwxyz23456789";/* generate a four-digit random number */for ($ I = 0; $ I <4; $ I ++) {$ num. = substr ($ str, rand (), 1) ;}$ _ SESSION ['code'] = $ num; // Save the random number to the session $ im = imagecreate (60, 25); // create an image of 60*20 $ white = ImageColorAllocate ($ im, 255,255,255 ); // set the background color of the image to white $ blue = ImageColorAllocate ($ im, 255 ); // set the text color in the image to blue/* Add multiple numbers with different colors to the image */for ($ I = 1; $ I <200; $ I ++) {$ x = rand (200,255-9); $ y = rand (-6); $ color = imagecolorallocate ($ im, rand ), rand (200,255), rand (200,255); imagechar ($ im, 1, $ x, $ y, "*", $ color );} /* Add a four-digit random number to the image. the position is not fixed. */$ strx = rand (); for ($ I = 0; $ I <4; $ I ++) {$ strpos = rand (1, 6); imagestring ($ im, 5, $ strx, $ strpos, substr ($ num, $ I, 1 ), $ blue); $ strx + = rand (8, 12);} header ("Content-type: image/gif"); // set the format of the output image imagegif ($ im ); // output image imagedestroy ($ im); // release image resources // return $ _ SESSION ['code']; exit ;}}$ auth = new auth ();
Html display
HTML code
Verification code: Click image refresh
------ Solution --------------------
If you have a problem, you should switch to your own system/browser. In addition, check the number of others and determine whether there are problems with your system or server code.
------ Solution --------------------
Check whether session. autostart is enabled.
------ Solution --------------------
Discussion
The machines are all changed, and the system is also new.
------ Solution --------------------
First, check whether session. autostart is enabled.
But other browsers are okay, that is, my machine is faulty. This is not the reason.
You have to check whether your browser allows cookies.
No problem with the code itself
If src = "{$ baseurl}/auth. php" is displayed in html, this is obviously incorrect.
The template is similar.
------ Solution --------------------
The path may be wrong.
/Auth. php "...;