1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

geo redirect which work with https

Discussion in 'HTML & JavaScript' started by james250, Dec 10, 2014.

  1. james250

    james250 Newbie

    Joined:
    Aug 25, 2010
    Messages:
    48
    Likes Received:
    1
    Code:
    <head>
    <script src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>
    <script type="text/javascript">
    
        switch(geoplugin_countryCode()){
            case "US" :
                document.location.href = "https://yahoo.com/";
                break;
            case "GB" :
                document.location.href = "https://yahoo.com/"
                break;
            case "CA" :
                document.location.href = "https://yahoo.com/"
                break;
             default :
                document.location.href = "https://google.com/"
                break;
        }
    </script>
    </head>
    
    this geo redirect code worked properly, but if i use https in my domain it wont work. can anyone help me to run geo redirect this or any which work in https.

    thanks
     
  2. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    950
    Likes Received:
    662
    Occupation:
    Web/Bot Developer
    Strange cause the above code works for me using https. What kind of error are you seeing?
     
    Last edited: Dec 10, 2014
  3. laowai

    laowai Power Member

    Joined:
    Feb 27, 2011
    Messages:
    522
    Likes Received:
    184
    Try to replace this:
    <script src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>

    with this:
    <script src="https://www.geoplugin.net/javascript.gp" type="text/javascript"></script>
     
  4. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    950
    Likes Received:
    662
    Occupation:
    Web/Bot Developer
    Or better yet:
    <script src="//www.geoplugin.net/javascript.gp" type="text/javascript"></script>

     
    • Thanks Thanks x 1
  5. james250

    james250 Newbie

    Joined:
    Aug 25, 2010
    Messages:
    48
    Likes Received:
    1
    nothing error show, see this : https://profilefbviews.com/test.php .

    can you show your link
     
  6. james250

    james250 Newbie

    Joined:
    Aug 25, 2010
    Messages:
    48
    Likes Received:
    1
    i already try this, not working
     
  7. james250

    james250 Newbie

    Joined:
    Aug 25, 2010
    Messages:
    48
    Likes Received:
    1
    i try this too, not working
     
  8. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    950
    Likes Received:
    662
    Occupation:
    Web/Bot Developer
    Try this in straight PHP:
    Code:
    <?php
    $location_data_json= file_get_contents('http://www.geoplugin.net/json.gp?ip='.$_SERVER['REMOTE_ADDR']);
    $location_data_array = json_decode($location_data_json);
    switch ($location_data_array->geoplugin_countryCode) {
        case "US":
            header("Location: https://google.com/");
            break;
        case "GB":
            header("Location: https://google.co.uk/");
            break;
        case "CA":
            header("Location: https://google.ca/");
            break;
        default:
            header("Location: https://google.com/");
    }
    ?>
    
     
  9. james250

    james250 Newbie

    Joined:
    Aug 25, 2010
    Messages:
    48
    Likes Received:
    1

    thanks mate, finally worked :)