Try to use this, random not php, but JS.
function refresh_captcha()
{
var img = document.getElementById('captchaimg');
img.src = 'captcha_code_file.php?rand=' + Math.random();
document.getElementById ("captchaimg").src = img.src;
//alert("some alert.");
}