A common way of doing this is to load the thankyou page with a querystring of where the redirect is going to go.
Originally Posted by bladysh
Then, the thankyou.php page sets a timed meta-redirect to the place in the querystring.
I'm not in a position to test as of this moment, but something like that does the job.
$location = filter_input(INPUT_GET, 'return', FILTER_SANITIZE_URL);
echo '<meta http-equiv="refresh" content="10;url=http://' + $_SERVER['PHP_HOST'] + '/' + $location + '">';