If I need to be 100% sure that the button will work I pass the referring page along in the URI. If you use sessions than just remember the last page in your session container and use that URI.
The code looks good Birdman. I´d use the $_SERVER['HTTP_REFERER'] superglobal just to be sure. Checking whether the referrer is a valid URI and on your domain might be a good idea as well. After all this could be anything1, so simply echoing it will open up your site to all kinds of code injections vulnerabilities.
1 Some people around here are known to put rather large strings into the HTTP request headers´ User-agent field. ;) The same could be done with the Referer field as well.