Examples of generating sessionid and random passwords

Source: Internet
Author: User
Tags add numbers chr
This can be used to authenticate users and generate random passwords--teaman
?
//----------------------------------------------------
Function GetSID ()
//
Parameters: $nSize number of caracters, default 24
return value:24 caracters string
//
Description:this function returns a random string
Caracters that can is used to identify users
On your Web site in a more secure way. You can also
Use this function to generate passwords.
//----------------------------------------------------
function GetSID ($nSize =24) {

Randomize
Mt_srand (Double) microtime () * 1000000);
for ($i =1; $i <= $nSize; $i + +) {

If you wish to add numbers in your string,
Uncomment the two lines that are commented
In the IF statement
$nRandom = Mt_rand (1,30);
if ($nRandom <= 10) {
Uppercase letters
$sessionID. = Chr (Mt_rand (65,90));
} elseif ($nRandom <= 20) {
$sessionID. = Mt_rand (0,9);
} else {
lowercase letters
$sessionID. = Chr (Mt_rand (97,122));
}

}
return $sessionID;
}
Test the function
Echo GetSID (16);
?>

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.