you're echoing out rand_string before it's set by image.php. of course it wouldn't be the same. you have to set it by calling image.php, and then echo it.