Jump to content

Recommended Posts

Hi,

 

Does anyone know how to create a php file which will ask the user to enter three random characters from their pre-selected word. It would be like with online banking where you have to enter for example letters 2, 4 and 5 from your memorable data.  Any help would be greatley appreciated.

 

Thanks

This should get you started

// Set secret word
$word = 'mysecretword';

// How many letters must they provide
$required_letters = 3;

// Populate array with letters keyed on their position
$letters = array();
while (count($letters) < $required_letters){
    $k = rand(1, strlen($word));
    $letters[$k] = substr($word, $k-1, 1);
}

// Sort if you want them to enter the letters in order
ksort($letters);

// Print array
echo '<pre>';
print_r($letters);
echo '</pre>';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.