make a session user have a automatic code input
when a user logs i开发者_开发百科n, I want a input type text to be already filled with some pre-determined letter...
how can I make that possible?
You can do it in two ways:-
You can give control from the Admin area, so that the Administrator has the full control. This can be possible by providing a list drop down with all the recommended alphabets, in the Settings section of your Admin area, and let the Admin choose her preferred alphabet & store it in the database. Then you can retrieve it from the database & show it in the front-end when any user logs in.
When the user logs in, you can generate a random letter, using the PHP function "
rand()
".
One simple code snippet for the second solution will be:-
<?php
// This function considers both the cases for each of the letters.
function randLetter() {
$int = rand(0, 51);
$a_z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$rand_letter = $a_z[$int];
return $rand_letter;
}
/**
* This function considers only one specific cases for each of the letters.
*/
function randSpecificCaseLetter($lower_case = TRUE) {
if ($lower_case) {
$letter = chr(rand(97, 122));
}
else {
$letter = chr(rand(65, 90));
}
return $letter;
}
?>
Hope it helps.
精彩评论