CPAElites is for sale! As a result of the 2 months CEO absence: Please click [here] to read more!


[Q?] Redirect By Country On Wordpress ? Please help :(
2014-01-04, 08:18 PM, (This post was last modified: 2014-01-04, 08:18 PM by victor.)
#1
how can I redirect visitors by country on my wordpress website ? I tried a lot of plug-ins but non of them work :( Do I need to do something with cpanel or anything ? please help
Reply
2014-01-04, 08:20 PM, (This post was last modified: 2014-01-04, 08:25 PM by Atlantis.)
#2
It is possible with javascript. Actually, someone here on cpaelites shared a tutorial before. Wait a sec. I'll look if I can find it for you.

EDIT: http://www.cpaelites.com/Thread-Mobile-S...ery+mobile
You can modify that method to make a geo-based redirect.


[Image: wI9cuAG.png]
Reply
2014-01-05, 02:43 PM,
#3
Yes you can do it with javascript but it would be cleaner to do it with php.
I modified the script for you that the other user posted:
Code:
<?php
$ip  = (isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']));
$country = (filter_var($ip, FILTER_VALIDATE_IP) ? (!empty(json_decode(file_get_contents("http_//www.geoplugin.net/json.gp?ip=".$ip))->geoplugin_countryCode)? json_decode(file_get_contents("http_//www.geoplugin.net/json.gp?ip=".$ip))->geoplugin_countryCode : "unknown") : "unknown");
   switch ($country) {
        case "FR":
        echo "this is fr";
        break;
        default:
        echo "if not defined";
   }

Replace http_ with correct http: I can't post urls yet.
I'm gonna post javascript version too in a sec
Reply
2014-01-05, 02:47 PM,
#4
(2014-01-05, 02:43 PM)apladas Wrote: Yes you can do it with javascript but it would be cleaner to do it with php.
I modified the script for you that the other user posted:
Code:
<?php
$ip  = (isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']));
$country = (filter_var($ip, FILTER_VALIDATE_IP) ? (!empty(json_decode(file_get_contents("http_//www.geoplugin.net/json.gp?ip=".$ip))->geoplugin_countryCode)? json_decode(file_get_contents("http_//www.geoplugin.net/json.gp?ip=".$ip))->geoplugin_countryCode : "unknown") : "unknown");
   switch ($country) {
        case "FR":
        echo "this is fr";
        break;
        default:
        echo "if not defined";
   }

Replace http_ with correct http: I can't post urls yet.
I'm gonna post javascript version too in a sec

thank you so much sir :) Trying it now
Reply
2014-01-05, 02:52 PM, (This post was last modified: 2014-01-05, 02:58 PM by apladas.)
#5
Sorry this can't be done with javascript using that provider because their server doesn't accept ajax requests from another server. I'll see if I can find an alternative.
Update: found alternative.

Javascript version, make sure to add jQuery before this:

Code:
<script>
            $.ajax({
                url: 'http_//ip-api.com/json',
                dataType: 'json',
                success: function(data)
                {
                if (data.status == 'success') {
                switch(data.countryCode)
                    {
                        case "FR":
                        alert('if FR');
                        break;
                        default:
                        alert('if not set');
                    }    
                }
                }
            });

    </script>

Again make sure to replace http_ with http:
Reply


Related Threads
Thread Author Replies Views Last Post
  OGAds offer API output help please AbdouMotDz 3 2,930 2020-04-24, 01:52 AM
Last Post: WORLD_PEACE
  OfferToro Postback Help Socialhits 5 2,470 2020-04-06, 04:55 PM
Last Post: thysdw
  referral link wordpress plugin/html code Anger77x 0 359 2019-06-30, 09:41 AM
Last Post: Anger77x
  [Help] Angular Niki 0 350 2019-05-18, 10:46 PM
Last Post: Niki
  Need Few Instructions That Can Help me Create Video Whiteboard Animation EvaHarrison 1 741 2018-08-17, 02:23 PM
Last Post: CharlieHarper





About Us | Contact Us | CPAElites | Advertise | Stats

Copyright © 2013 - 2020 by (company to be announced later)
Temporarily (!) powered by MyBB, fixed (repaired) and enhanced by Charlie Harper (GitHub) aka Charles Francis Harper (Wikipedia)
Return to top
This forum uses Lukasz Tkacz MyBB addons.