Fatal error: Cannot redeclare function

This is the example code to fix the fatal error and redirect user as per the given page id. You can further optimise the code, if the redirection is going to remain same for “DE” and “US” for all the pages, you can just skip the if ( is_page( 90 ) ) check for these country codes.

add_action( 'template_redirect', 'geoip_redirect', 5 );

function geoip_redirect() {

    //Return if not admin, or the blog id is not 123, or not on the specified page, or if the function doesn't exists
    //List of pages to redirect from
    $pages = array(
        50,
        90
    );
    //Return if not admin, or the blog id is not 123, or not on the specified page, or if the function doesn't exists
    if ( is_admin() || 123 !== get_current_blog_id() || ! is_page( $pages ) || ! function_exists( 'geoip_detect2_get_info_from_current_ip' ) ) {
        return;
    }

    $userInfo    = geoip_detect2_get_info_from_current_ip();
    $countryCode = $userInfo->country->isoCode;

    if ( is_page( 90 ) ) {
        switch ( $countryCode ) {
            case 'DE':
                $redirect_to = '/germany';
                break;
            case 'US':
                $redirect_to = '/usa';
                break;
            case 'SG':
                $redirect_to = 'www.google.com.sg';
                break;
            default:
                $redirect_to = 'www.google.com.sg';
        }
    } elseif ( is_page( 50 ) ) {
        //Change URL accordingly
        switch ( $countryCode ) {
            case 'DE':
                $redirect_to = '/germany';
                break;
            case 'US':
                $redirect_to = '/usa';
                break;
            case 'SG':
                $redirect_to = 'www.amazon.com.sg';
                break;
            default:
                $redirect_to = 'www.amazon.com.sg';
        }
        //So on you can add additional else if conditions for rest of your pages
    }

    if ( ! empty( $redirect_to ) ) {
        if ( stripos( $redirect_to, 'http' ) === 0 ) {
            wp_redirect( $redirect_to ); // Full URL.
        } else {
            wp_redirect( home_url( $redirect_to ) ); // Local /path.
        }
        exit;
    }
}

This code is suitable if redirection is gonna remain same for “US” and “DE”

add_action( 'template_redirect', 'geoip_redirect', 5 );

function geoip_redirect() {

    //List of pages to redirect from
    $pages = array(
        50,
        90
    );
    //Return if not admin, or the blog id is not 123, or not on the specified page, or if the function doesn't exists
    if ( is_admin() || 123 !== get_current_blog_id() || ! is_page( $pages ) || ! function_exists( 'geoip_detect2_get_info_from_current_ip' ) ) {
        return;
    }

    $userInfo    = geoip_detect2_get_info_from_current_ip();
    $countryCode = $userInfo->country->isoCode;

    if ( in_array( $countryCode, array( "US", "DE" ) ) ) {
        $redirect_to = 'US' == $countryCode ? '/usa' : '/germany';
    } else {
        if ( is_page( 90 ) ) {
            switch ( $countryCode ) {
                case 'SG':
                    $redirect_to = 'www.google.com.sg';
                    break;
                default:
                    $redirect_to = 'www.google.com.sg';
            }
        } elseif ( is_page( 50 ) ) {
            //Change URL accordingly
            switch ( $countryCode ) {
                case 'SG':
                    $redirect_to = 'www.amazon.com.sg';
                    break;
                default:
                    $redirect_to = 'www.amazon.com.sg';
            }
        }
    }
    if ( ! empty( $redirect_to ) ) {
        if ( stripos( $redirect_to, 'http' ) === 0 ) {
            wp_redirect( $redirect_to ); // Full URL.
        } else {
            wp_redirect( home_url( $redirect_to ) ); // Local /path.
        }
        exit;
    }
}

Well, you can further optimise the code, depending upon what are the redirection values for your 15 pages, if it’s all similar you can definitely come up with ways to minimise the code.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)