The verification code is required for background login, and SessionID is required for foreground User tracking. Of course, the default PHP will have a SessionID after the Session is enabled, but I need my own, and can be stored in the database, so I tried to construct the following functions.
/****** Generate the Session ID ******/
The basic idea is to get the time of the current microsecond, then generate a random number, add the random number and the current time, encrypt it, and finally extract the required length.
/*
Function Name: create_sess_id ()
Function: generate a random session ID.
Parameter: $ len: the length of the session string. The default value is 32 bits, not lower than 16 bits.
Return Value: the ID of the returned session.
Function heiyeluren
*/
Function create_sess_id ($ len = 32)
{
// Check whether the submitted length is valid
If (! Is_numeric ($ len) | ($ len> 32) | ($ len <16) {return ;}
// Obtain the microseconds of the current time
List ($ u, $ s) = explode ('', microtime ());
$ Time = (float) $ u (float) $ s;
// Generate a random number
$ Rand_num = rand (100000,999 999 );
$ Rand_num = rand ($ rand_num, $ time );
Mt_srand ($ rand_num );
$ Rand_num = mt_rand ();
// Generate SessionID
$ Sess_id = md5 (md5 ($ time). md5 ($ rand_num ));
// Intercept the specified SessionID.
$ Sess_id = substr ($ sess_id, 0, $ len );
Return $ sess_id;
}
/****** Generate the verification code ******/
Idea: this idea is relatively simple. Considering uniqueness and randomness, we can extract a string from the Session ID in the verification code, because our SessionID is unique.
/*
Function Name: create_check_code ()
Function: generate a Random verification code.
Parameter: $ len: length of the verification code. The value must be no longer than 16 digits. The default value is 4 digits.
Return Value: return the verification code of the specified length.
Function heiyeluren
*/
Function create_check_code ($ len = 4)
{
If (! Is_numeric ($ len) | ($ len> 6) | ($ len <1) {return ;}
$ Check_code = substr (create_sess_id (), 16, $ len );
Return strtoupper ($ check_code );
}
/****** Image for generating the verification code ******/
This is something simple for PHP image programming. I made images and they are simple.
/*
Function Name: create_check_image ()
Function function: generates an image of the verification code.
Parameter: $ check_code: check code string, which is generally obtained by the create_check_code () function.