IPv4 only with PHP with ipv4 / ipv6 link

2

I've always used $_SERVER['REMOTE_ADDR'] to get the IP user / visitor on some systems.

But I started to use a fixed IP at work, which is IPV4 , but when I go to see the registry I have accessed IPV6 .

But on sites like forums and blogs their systems in PHP register IPV4 , and I analyzed the codes and even then I could not understand the algorithm that can pass the IPV6 or another method for IPV4 .

So I believe it's only possible with PHP, if anyone can help me.

Edition: I installed the SMF2 that I am used to in a free hosting (outside my network) and I tested it, instead of registering the IPV4 registered the same IPV6, this is making me a bit confused:

Why on other personal sites that use the same system show my IPV4.

    
asked by anonymous 05.02.2018 / 18:36

1 answer

1

I've been able to figure out why some websites get IPV4 even using IPV6 at the same time and my hosting does not, the routes used may vary from the server where the PHP script was hosted, so there's really no way to do it without using of third-party service.

Now a workaround, it's worth noting that I will not post the third-party service I used because I think it's frowned upon by the community, and that too can be considered a poorly done system.

In order to solve this problem, I used this service to convert the IPV4 to JSON:

http://<ipv4 ipv6 service>/json/widgetdata.php?callback=_jqjsp&_1518034744039=

It returns a JSON:

_jqjsp({"address":"179.XXX.XXX.XX5","proto":"ipv4","country_code":"BR","country":"Brazil"})

But you can not use xmlHTTPrequest to receive values from another JSON from another hosting, so through its URL I've changed the term of the callback variable so that gambiarra making PHP service to create a Javascript variable using the equal sign (=) so% 3D for URL to accept:

http://<ipv4 ipv6 service>/json/widgetdata.php?callback=dataipv4%3D

And by calling it HTML the variable is accessible to your browser as a JSON object:

var dataipv4=({"address":"177.XXX.XXX.XX5","proto":"ipv4","country_code":"BR","country":"Brazil"})

So now with xmlHTTPRequest, just use the dataipv4.address variable to get the IP and send it by GET method to a PHP that uses IP:

function showIpv(ip) {
     var xmlhttp = new XMLHttpRequest();
     xmlhttp.onreadystatechange = function() {
         if (this.readyState == 4 && this.status == 200) {
            console.log()
         }
     };
     xmlhttp.open("GET", "write_ipv4.php?ip="+ip, true);
     xmlhttp.send();
}

The write_ipv4.php file that stays in the hosting:

<?php
if(isset($_GET['ip']) && !empty($_GET['ip'])){
   /* User a variavel global $_GET['ip'] da maneira que preferir 
      Por exemplo:
      echo $_GET['ip']
      retorna o IP no formato XXX.XXX.XXX.XXX
   */
}else{
   console.log('Acesso direto proibido');
}
?>
    
08.02.2018 / 01:12