(help)country based url redirecting ???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    (help)country based url redirecting ???

    hi,
    i want to redirect indian user's to a page and all other country's user to another page?
    how to do it?

    http://WapTops.com- Get Real High Traffic
    http://WapFun.info-Fun 4 Wap

    #2
    PHP Code:
    <?php 
    $ip
    =$_SERVER['REMOTE_ADDR']; 
     
    geoCheckIP($ip); 
       
               

           
    //Get an array with geoip-infodata 
           
    function geoCheckIP($ip
           { 
                   
    //check, if the provided ip is valid 
                   
    if(!filter_var($ipFILTER_VALIDATE_IP)) 
                   { 
                           throw new 
    InvalidArgumentException("IP is not valid"); 
                   } 

                   
    //contact ip-server 
                   
    $response=@file_get_contents('http://www.netip.de/search?query='.$ip); 
                   if (empty(
    $response)) 
                   { 
                           throw new 
    InvalidArgumentException("Error contacting Geo-IP-Server"); 
                   } 
        
    //Array containing all regex-patterns necessary to extract ip-geoinfo from page 
                  
    $patterns=array(); 
                   
    $patterns["domain"] = '#Domain: (.*?)&nbsp;#i'
                   
    $patterns["country"] = '#Country: (.*?)&nbsp;#i'
                   
    $patterns["state"] = '#State/Region: (.*?)<br#i'
                   
    $patterns["town"] = '#City: (.*?)<br#i'


                
                   
    //Array where results will be stored 
                   
    $ipInfo=array(); 

                   
    //check response from ipserver for above patterns 
                   
    foreach ($patterns as $key => $pattern
                   { 
                           
    //store the result in array 
                           
    $ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : 'not found'
                   } 

                   return 
    $ipInfo
           } 
    $my_array=geoCheckIP($ip); 

    foreach (
    $my_array as $key => $value){ 
     if(
    $key=='country'){ 
     
    #switch on the country: 
     
    switch ($value) { 
     case 
    'IN - India'
     echo 
    "('header : ../index2.php')"
     break; 
    default :
    echo 
    "('header : ../index3.php')":
     break; 
      } 
     } 


    ?>


    all indian users redirect to index2.php page and othe country user index3.php page. Call this in in your top of index page using include function.

    Comment


      #3
      its just printing
      ('header : ../index2.php')";

      http://WapTops.com- Get Real High Traffic
      http://WapFun.info-Fun 4 Wap

      Comment


        #4
        fix quotes and single quotes arround.

        Comment


          #5
          Switch should be like this
          PHP Code:
          switch ($value) { 
           case 
          'IN - India'header('Location:../index2.php'); 
           break; 
          default : 
          header('Location:../index3.php');
           break; 
            } 
          libra.wen.ru

          Comment


            #6
            Originally posted by s3nzo View Post
            Switch should be like this
            PHP Code:
            switch ($value) { 
             case 
            'IN - India'header('Location:../index2.php'); 
             break; 
            default : 
            header('Location:../index3.php');
             break; 
              } 


            working thanks

            http://WapTops.com- Get Real High Traffic
            http://WapFun.info-Fun 4 Wap

            Comment


              #7
              if ip is wrong, then how to redirect it to other page?????

              http://WapTops.com- Get Real High Traffic
              http://WapFun.info-Fun 4 Wap

              Comment


                #8
                Originally posted by slowy View Post
                if ip is wrong, then how to redirect it to other page?????
                You mean if the user is behind a proxy?
                I need some facebook likes, can you please help me
                http://facebook.com/softwarefreakin
                I noticed social media is really powerful
                Well DONE is better than well SAID

                Comment


                  #9
                  Originally posted by softwarefreak View Post
                  You mean if the user is behind a proxy?
                  ya if user is behind anonymous proxy then country is showing empty so i want to reirect these users to another page

                  http://WapTops.com- Get Real High Traffic
                  http://WapFun.info-Fun 4 Wap

                  Comment


                    #10
                    PHP Code:
                    <?php
                    function gum_real_ip()  
                    {  
                        
                    $keyname_ip_arr = array('HTTP_X_FORWARDED_FOR''HTTP_REMOTE_ADDR_REAL''HTTP_CLIENT_IP''HTTP_X_REAL_IP''REMOTE_ADDR');  
                        foreach (
                    $keyname_ip_arr as $keyname_ip) {  
                            if (!empty(
                    $_SERVER[$keyname_ip])) {  
                                
                    $ip $_SERVER[$keyname_ip];  
                                break;  
                            }  
                        }  
                        if (
                    strstr($ip',')) { 
                            
                    $ips explode(','$ip); 
                             if(
                    substr($ips[0], 13)=='10.'&&strlen($ips[1])>5
                                
                    $ip trim($ips[1]); 
                            else 
                    $ip trim($ips[0]); 
                        }  
                        if(!
                    preg_match("^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}^"$ip)) $ip $_SERVER["REMOTE_ADDR"];  
                        return 
                    $ip
                        list(
                    $ip1,$ip2,$ip3,$ip4) = explode('.',$ip);  
                        return 
                    $ip1.'.'.$ip2.'.'.$ip3.'.0'//REAL IP  
                    }  
                    $ip gum_real_ip();
                    //& continue with the below code
                    I need some facebook likes, can you please help me
                    http://facebook.com/softwarefreakin
                    I noticed social media is really powerful
                    Well DONE is better than well SAID

                    Comment


                      #11
                      PHP Code:
                      <?php 
                      function gum_real_ip()   
                      {   
                          
                      $keyname_ip_arr = array('HTTP_X_FORWARDED_FOR''HTTP_REMOTE_ADDR_REAL''HTTP_CLIENT_IP''HTTP_X_REAL_IP''REMOTE_ADDR');   
                          foreach (
                      $keyname_ip_arr as $keyname_ip) {   
                              if (!empty(
                      $_SERVER[$keyname_ip])) {   
                                  
                      $ip $_SERVER[$keyname_ip];   
                                  break;   
                              }   
                          }   
                          if (
                      strstr($ip',')) {  
                              
                      $ips explode(','$ip);  
                               if(
                      substr($ips[0], 13)=='10.'&&strlen($ips[1])>5)  
                                  
                      $ip trim($ips[1]);  
                              else 
                      $ip trim($ips[0]);  
                          }   
                          if(!
                      preg_match("^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}^"$ip)) $ip $_SERVER["REMOTE_ADDR"];   
                          return 
                      $ip;  
                          list(
                      $ip1,$ip2,$ip3,$ip4) = explode('.',$ip);   
                          return 
                      $ip1.'.'.$ip2.'.'.$ip3.'.0'//REAL IP   
                      }   
                      function 
                      geoCheckIP($ip)  
                             {  
                                     
                      //check, if the provided ip is valid  
                                     
                      if(!filter_var($ipFILTER_VALIDATE_IP))  
                                     {  
                                             throw new 
                      InvalidArgumentException("IP is not valid");  
                                     }  

                                     
                      //contact ip-server  
                                     
                      $response=@file_get_contents('http://www.netip.de/search?query='.$ip);  
                                     if (empty(
                      $response))  
                                     {  
                                             throw new 
                      InvalidArgumentException("Error contacting Geo-IP-Server");  
                                     }  
                          
                      //Array containing all regex-patterns necessary to extract ip-geoinfo from page  
                                    
                      $patterns=array();  
                                     
                      $patterns["domain"] = '#Domain: (.*?)&nbsp;#i';  
                                     
                      $patterns["country"] = '#Country: (.*?)&nbsp;#i';  
                                     
                      $patterns["state"] = '#State/Region: (.*?)<br#i';  
                                     
                      $patterns["town"] = '#City: (.*?)<br#i';  


                                   
                                     
                      //Array where results will be stored  
                                     
                      $ipInfo=array();  

                                     
                      //check response from ipserver for above patterns  
                                     
                      foreach ($patterns as $key => $pattern)  
                                     {  
                                             
                      //store the result in array  
                                             
                      $ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : 'not found';  
                                     }  

                                     return 
                      $ipInfo;  
                             }
                      $ip gum_real_ip(); 
                      $my_array=geoCheckIP($ip);  

                      foreach (
                      $my_array as $key => $value){  
                       if(
                      $key=='country'){  
                       
                      #switch on the country:  
                       
                      switch ($value) {  
                       case 
                      'IN - India':  
                       
                      header("location:indian_visitors.php");
                       break;  
                      default : 
                       
                      header("location:other_visitors.php");
                       break;  
                        }  
                       }  

                      }  
                      ?>
                      This shud work now..
                      Last edited by softwarefreak; 25.01.12, 17:31.
                      I need some facebook likes, can you please help me
                      http://facebook.com/softwarefreakin
                      I noticed social media is really powerful
                      Well DONE is better than well SAID

                      Comment


                        #12
                        here other_visitors =anonymous proxy users?

                        http://WapTops.com- Get Real High Traffic
                        http://WapFun.info-Fun 4 Wap

                        Comment


                          #13
                          Originally posted by slowy View Post
                          here other_visitors =anonymous proxy users?
                          NO :D,the real ip will be detected(even if they are using proxy) & then they will be redirected like b4,other_visitors.php is the location you want to send ppl from countries other than India
                          I need some facebook likes, can you please help me
                          http://facebook.com/softwarefreakin
                          I noticed social media is really powerful
                          Well DONE is better than well SAID

                          Comment

                          Working...
                          X