I have built a simple CAPTCHA PHP script and now I am trying to create a script that generates a mp3 audio for people who can't see well or can't see at all. My goal is only to challenge myself, so I prefer not to use a external library, but I would appreciate some help. I tried using file_put_contents() function to merge the audios (I have one mp3 audio for each letter) and for my surprise, it worked, but it seemed incorrect to me to just join audio files like I would join text files. So my second attempt is to do like so:
<?php
session_start();
$letter_array = str_split($_SESSION["captcha"]); //this is an array with the letters of the captcha
header('Content-Type: audio/mpeg');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: 0');
$audio = '';
foreach ($letter_array as $letter) {
$audio .= file_get_contents("audios/".$letter.".mp3");
}
echo $audio;
?>
and then I can embed this file to an tag in HTML and it also works. I know that essentially both of the solutions are similar, but I find this second way more concise. My question is: although it works fine, is it OK to do such thing this manner, or is it wrong, or not recommended? I don't know much encoding and about the structure of a mp3 file, so I dont' know if this solution would work for everyone. I am also open to suggestions
Thanks