My web application allows me to tell the login form to redirect to a certain page on the website after successfully logging in. For example, if the user goes to the url http://localhost/login.php?returnto=%2FconfirmEmail.php, then after completing the login process, they will automatically be redirected to http://localhost/confirmEmail.php.
After completing the login process, I used the following code to validate the url:
function isValidReturnURL( $input ) {
    if ( !is_string( $input ) ) { //Input is not a string
        return FALSE;
    }
    $cleanString = trim( urldecode( $input ) );
    if ( !strlen( $cleanString ) ) { //Input is an empty string
        return FALSE;
    }
    //Edit: I updated the following code (see below)
    $urlHost = parse_url( $cleanString, PHP_URL_HOST );
    if ( !empty($urlHost) ) { //All local urls will be relative
        return FALSE;
    }
    //End edit
    return TRUE;
}
if ( isValidReturnURL( $_GET["returnto"] ) && $continue ) {
    header("Location:" . urldecode( $_GET["returnto"] ) );
}
I'd like to know if this code is secure, or will it still be possible for an attacker to cause the page to redirect to an external website (or to other malicious locations)?
Update: Previously, my code to ensure that the links were local was as follows:
...
if ( $cleanString[0] !== '/' ) { //All local urls should start with '/'
    return FALSE;
}
...
As noted by various comments, this will consider protocol relative URLS (e.g. //google.com) to be valid. I therefore updated the code above to take that into consideration.
urlencode('//google.com')returnstruereturnto=http://google.com%2540evil.com. All GET/POST values areurldecoded()by the platform, callingurldecode()in PHP means you decode the value twice and this double-decode will change how the URL is parsed.