[Q?] Redirect By Country On Wordpress ? Please help :(
2014-01-04, 11:48 PM,
(This post was last modified: 2014-01-04, 11:48 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, 11:50 PM,
(This post was last modified: 2014-01-04, 11:55 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, 06:13 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
Latest Thanks - View all

victor(2014-01-05 06:16 PM) 
Reply
2014-01-05, 06:17 PM,
#4
(2014-01-05, 06:13 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, 06:22 PM,
(This post was last modified: 2014-01-05, 06:28 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:
Latest Thanks - View all

victor(2014-01-05 06:42 PM) 
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Need a loading progress bar for wordpress! YoungArt 6 168 2017-08-26, 06:01 PM
Last Post: YoungArt
  ANNOUNCEMENT How To Protect And Secure Your WordPress Websites For Free [HawkEye Guide] HawkEye 22 5,677 2017-07-03, 03:45 AM
Last Post: alexoron
  [HELP NEEDED] Embedding P*rn videos to my adult WordPress Site nudes 15 1,779 2017-06-16, 02:09 PM
Last Post: tropicallad
  Work on Wordpress with hosting only Leo 4 749 2016-12-19, 01:20 AM
Last Post: ArtoAllan
  Choosing the right wordpress theme kalekoppen 10 2,154 2016-11-19, 05:15 AM
Last Post: $chestofloot$




About Us | Contact Us | CPA Elites | Advertise | Stats | Staff Team

© 2013-2017 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top