it's better to use headers than JavaScript if you want to redirect; you can always show the error message on the next page.

PHP Code:
// Redirect
header("Location: " $url);