1
Hello. I developed a simple CAPTCHA in PHP and now I’m trying to make a script that generates an audio from the generated code. I have an mp3 audio for each letter and number, and my momentary solution is the following:
<?php
session_start();
$vetorLetras = str_split($_SESSION['captcha']); //esse é o código gerado pelo CAPTCHA
header('Content-Type: audio/mpeg');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: 0');
foreach ($vetorLetras as $letra) {
echo file_get_contents('audios/'.$letra.'.mp3');
}
?>
And this code works perfectly! The result is exactly as expected, just call this file as an audio by the <audio> tag. But from what I’ve researched, it’s incorrect to do it this way, giving audio content echo that way. I’m now looking for a correct solution. I believe that in pure PHP it is not possible to join audios in a simple way. I was thinking of a script that runs on the client side that runs the audios of the code one at a time in sequence, but I don’t know how to do this safely, without showing the value of CAPTCHA in the source code, but I also don’t rule out the possibility of making audio by PHP, maybe in another format like WAV is possible. Someone knows how to do?