I'm using the following code to generate a random string:
<?php
function random_string( )
{
$character_set_array = array( );
$character_set_array[ ] = array( 'count' => 5, 'characters' => 'abcdefghijklmnopqrstuvwxyz' );
$character_set_array[ ] = array( 'count' => 1, 'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' );
$character_set_array[ ] = array( 'count' => 1, 'characters' => '0123456789' );
$character_set_array[ ] = array( 'count' => 1, 'characters' => '!@#$+-*&?:' );
$temp_array = array( );
foreach ( $character_set_array as $character_set )
{
for ( $i = 0; $i < $character_set[ 'count' ]; $i++ )
{
$temp_array[ ] = $character_set[ 'characters' ][ rand( 0, strlen( $character_set[ 'characters' ] ) - 1 ) ];
}
}
shuffle( $temp_array );
return implode( '', $temp_array );
}
?>
<?php echo random_string(); ?>
My question is - hopefully! - a simple one...
I'd like to re-use this random string elsewhere, say by calling $reuseablestring. Is this possible?
(To explain why I need to do this, I'm building a digital delivery system. The random string will be saved to a database and then passed, as a hidden form field to Google Checkout. Google then provides a link to the download page, with the random string attached. Once that page has been accessed, the status of the random string is changed to 'used' in the database, which will prevent the file being downloaded a second time).
Many, many thanks for your help. I really appreciate it!
Best wishes,
Martin