VB icon

Session ID

Email
Submitted on: 1/1/2015 3:45:00 AM
By: Benoit Gauthier (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 1555
 
     Generate a random string of caracters to use for identifying your users on your web site. Can also be used to generate passwords.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Session ID
//**************************************
No Copyrights, use as is.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Session ID
// Description:Generate a random string of caracters to use for identifying your users on your web site. Can also be used to generate passwords.
// By: Benoit Gauthier (from psc cd)
//
// Inputs:nSize , number of caracters for the string default =24
//
// Returns:A string with the random caracters in it.
//
// Assumes:Uses PHP.
//**************************************

<?
	//----------------------------------------------------
	// 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);
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.