生成sessionid和隨機(jī)密碼的例子
更新時(shí)間:2006年10月09日 00:00:00 作者:
用這個(gè)可以來驗(yàn)證用戶和生成隨機(jī)密碼--teaman
<?
//----------------------------------------------------
// Function GetSID()
//
// Parameters : $nSize number of caracters, default 24
// Return value : 24 caracters string
//
// Description : This function returns a random string
// of 24 caracters that can be 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);
?>
<?
//----------------------------------------------------
// Function GetSID()
//
// Parameters : $nSize number of caracters, default 24
// Return value : 24 caracters string
//
// Description : This function returns a random string
// of 24 caracters that can be 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);
?>
相關(guān)文章
Access數(shù)據(jù)庫(kù)導(dǎo)入Mysql的方法之一
Access數(shù)據(jù)庫(kù)導(dǎo)入Mysql的方法之一...2006-10-10PHP和Mysqlweb應(yīng)用開發(fā)核心技術(shù) 第1部分 Php基礎(chǔ)-3 代碼組織和重用2
創(chuàng)建可以調(diào)用的函數(shù)以便重用代碼把參數(shù)傳遞給函數(shù)并且從函數(shù)返回值和腳本的不同部分中的變量和數(shù)據(jù)進(jìn)行交互2011-07-07新手配置 PHP 調(diào)試環(huán)境(IIS+PHP+MYSQL)
新手配置 PHP 調(diào)試環(huán)境(IIS+PHP+MYSQL)...2007-01-01