Questions about saving the verification code in session
Source: Internet
Author: User
The question about saving the verification code in the session is that I generated the original character of the verification code on the code page and saved it to the session. how can the call from another page be blank? Strange code source Program & lt ;? Php & nbsp; // checkNum. php & nbsp; session_star session
How can I leave the original character of the verification code generated on the code page and save it to the session? Strange
Source code
// CheckNum. php
Session_start ();
Function random ($ len)
{
$ Srcstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
Mt_srand (); // Configure the random seed.
$ Strs = "";
For ($ I = 0; $ I <$ len; $ I ++ ){
$ Strs. = $ srcstr [mt_rand (0, 35)];
}
/*
2: strtoupper
3 Functions: converts all strings to uppercase \ r
4. return value: string
Method 5: strtoupper (string str );
6. note: This function converts all str strings to uppercase strings. \ R
Example 7:
8 strtoupper ("ab2cd4efg"); the result is AB2CD4EFG.
9 strtoupper ("ab1cde4fg"); the result is Ab1CDE4fg.
10
11 */
Return strtoupper ($ strs );
}
$ Str = random (4); // randomly generated string
$ Width = 50; // the image width of the verification code
$ Height = 25; // height of the verification code Image
/*
Content-Type: xxxx/yyyy
Location: xxxx: yyyy/zzzz
Status: nnn xxxxxx
*/
@ Header ("Content-Type: image/png ");
$ _ SESSION ["code"] = $ str;
// Echo $ str;
$ Im = imagecreate ($ width, $ height );
// Background color
$ Back = imagecolorallocate ($ im, 0xFF, 0xFF, 0xFF );
// Blur the vertex color
$ Pix = imagecolorallocate ($ im, 187,230,247 );
// Font color
$ Font = imagecolorallocate ($ im, 41,163,238 );
// Plot the vertices of fuzzy match.
Mt_srand ();
For ($ I = 0; I I <1000; $ I ++)
{
Imagesetpixel ($ im, mt_rand (0, $ width), mt_rand (0, $ height), $ pix );
}
Imagestring ($ im, 5, 7, 5, $ str, $ font );
Imagerectangle ($ im, 0, 0, $ width-1, $ height-1, $ font );
Imagepng ($ im );
Imagedestroy ($ im );
$ _ SESSION ["code"] = $ str;
Session_destroy ();
?>
Is calling $ _ SESSION ["code"] from another page empty? Why?
------ Solution --------------------
Session_destroy ();
You have deleted all sessions. how can I get session content on another page?
------ Solution --------------------
Session_destroy (); Dizzy. how do you get it if the session () has not been acquired?"
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