IPV4 only with PHP with ipv4/ipv6 link

Asked

Viewed 505 times

2

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

But I started using a FIXED IP at work, which is IPV4, but when I will see the record I agreed with IPV6.

But on websites like forums and blogs their PHP systems record the IPV4, and analyzed the codes and I still couldn’t understand the algorithm that can pass the IPV6 or other method for IPV4.

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

Edition: I installed the SMF2 I’m used to a free hosting (outside of my network) and tested, it instead of registering the IPV4 registered the same IPV6, this is making me somewhat confused: inserir a descrição da imagem aqui

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

  • https://tools.ietf.org/html/rfc8305

1 answer

1


I was 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 is really no way this can be done without using third party service.

Now an alternative solution, it is worth remembering that I will not post the third party service I used because I believe that this is poorly seen by the community, and that it can also be considered a poorly done system.

In order to solve I used this service to convert 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 cannot use xmlHTTPrequest to receive values from another JSON from another hosting, so through its URL I changed the term of the variable callback so that the gambiarra causing the service PHP to create a Javascript variable using the equal sign (=) so %3D to accept URL:

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

And 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 yes with xmlHTTPRequest it was enough to use the variable dataipv4.address to get the IP and send by GET method to a PHP that uses the 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 is 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');
}
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.