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');
}
?>