PHP generation SessionID and picture check code ideas and implementation _php tutorial

Source: Internet
Author: User
To do a background login need to use the check code, the front-end user tracking needs to use the SessionID, of course, the default PHP opened the session after a SessionID, but I need their own, and can be stored in the database, then I tried a bit, constructs the following function.
/****** generates session ID ******/
The basic idea: is to take the current microsecond time to obtain, and then generate a random number, the random number and the current time after the addition of encryption, and finally intercept the required length
/*
Function name: create_sess_id ()
Function: Generates a random session ID
Parameters: $len: The length of the session string is required, default is 32 bits, not less than 16 bits
Return Value: Return session ID
function Heiyeluren
*/
function create_sess_id ($len =32)
{
Verify the length of the commit is legal
if (!is_numeric ($len) | | ($len >32) | | ($len <16)) {return;}
Gets the current time in microseconds
List ($u, $s) = explode (' ', Microtime ());
$time = (float) $u (float) $s;
Generate a random number
$rand _num = rand (100000, 999999);
$rand _num = rand ($rand _num, $time);
Mt_srand ($rand _num);
$rand _num = Mt_rand ();
Produce SessionID
$sess _id = MD5 (MD5 ($TIME). MD5 ($rand _num));
Intercept a SessionID that specifies the length required
$sess _id = substr ($sess _id, 0, $len);
return $sess _id;
}

/****** Generate check Code ******/
Idea: This idea is relatively simple, because consider uniqueness and randomness, our check code on the session ID to intercept a string, because our SessionID is fully considered unique.
/*
Function name: Create_check_code ()
Function: Generates a random check code
Parameter: $len: Requires the length of the check code, please do not longer than 16 bits, the default is 4 bits
Return value: Returns a check 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 (), $len);
Return Strtoupper ($check _code);
}

/****** generate a picture of the checksum code ******/
This is some of the more simple PHP graphics programming things up, I made the pictures and simple.
/*
Function name: Create_check_image ()
Function: Produces a picture of a checksum code
Parameters: $check _code: Check code string, generally by the Create_check_code () function to obtain

http://www.bkjia.com/PHPjc/445209.html www.bkjia.com true http://www.bkjia.com/PHPjc/445209.html techarticle do a background login need to use the check code, the front-end user tracking needs to use SessionID, of course, the default PHP opened the session after a SessionID, but I need their own ...

  • Related Article

    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.