Questions about the session Save verification Code
Source: Internet
Author: User
Session Save Verification Code problem
I have saved the original character of the code page from the other page in the session. How can it be empty? Strange
SOURCE program for code
checknum.php
Session_Start ();
function Random ($len)
{
$srcstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Mt_srand ();//configuration of random seeds
$strs = "";
for ($i =0; $i < $len; $i + +) {
$strs. = $srcstr [Mt_rand (0,35)];
}
/*
2 Name: Strtoupper
3 function: string full capitalization \ r
4 return Value: string
5 Syntax: Strtoupper (string str);
6 Description: This function will turn the string str all the size of the string. \ r
7 Example:
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; Verify the width of the code picture
$height = 25; Verify the height of the code picture
/*
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 Point Color
$pix =imagecolorallocate ($im, 187,230,247);
Font Color
$font =imagecolorallocate ($im, 41,163,238);
The point of painting blur function
Mt_srand ();
for ($i =0; $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 ();
?>
Calling $_session["code" from another page is actually empty? Why
------Solution--------------------
Session_destroy ();
You have deleted the session, how can another page have the content of the session?
------Solution--------------------
Session_destroy (); Halo, you have not yet taken off the session () How do you take it? 》
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