Get IPv6 in PHP - php

Can some one help me to read out the IPv6?
I tried this Working with IPv6 Addresses in PHP but it does not work for me..
There is no problem to get the IPv4 over
echo $_SERVER['REMOTE_ADDR'];
but can someone tell me how i get the IPv6?
This Site can read both (IPv4 and IPv6): http://ipv6-test.com/api/. But I try it without any api, is that possible?
Thanks

You have the right idea, but the request has to be made with IPv6 if you want an IPv6 address.
The site you link to probably works by having a page that loads resource from a server only accessible via IPv6. If it works, then you know the address.
I would just build a site that fires off AJAX requests to the same server, one via IPv4 and one via IPv6. Use its IP addresses to rule out any local DNS issues where IPv6 may not be supported.

Related

get host ipv6 with PHP

I want to verify the Googlebot using the following function. But this function does not support ipv6
php document for gethostbyaddr()
One solution was mentioned in the link below, but it does not work :
A solution that does not work
I want to get the domain name and then match it with the following statements:
google.com
googlebot.com
In the following link, you can see examples of Google IP:
https://www.lifewire.com/what-is-the-ip-address-of-google-818153
Do you know a solution to this issue?
If the client sent the request using IPv4, then you'll get the IPv4 address. If your server is serving IPV6 they sent the request using IPv6, you'll get the IPv6 address.
A client will send a request to your server using only one protocol.

How to show the IPv4 and IPv6 adress from the website visitor

i have a litle php website which shows the ip adress from the visitor. I have seen other sites which can show the IPv4 and the IPv6 Adress. When i visit my page i only see the IPv6 adress. When i visit for example wieistmeineip.de i see both (even without javascript). I think they let the client make a second request on a server that only excepts IPv4. Have any one a solution for that? What would be the easiest way to only except IPv4 on an second server and to get both request from the client?
Thanks a lot
Frank

Ger users IPv4 address through cloudflare and azure

I have created a web app through azure that entirely depends on a users location to give them the correct data e.t.c. It's an app that recommends places to go locally.
I'm using azure, cloudflare and codeigniter as the frame work.
I'm really getting stressed out, as when i'm home, i'm getting the right location, but the second i go on my website anywhere else, it never gets the accurate information.
When cheking the header $_SERVER['HTTP_CF_CONNECTING_IP']; i seem to be getting an ipv6 address, when i go to ipdata.co, their site loads my ipv4 address which gives exact accurate information. But when i enter the address from $_SERVER['HTTP_CF_CONNECTING_IP']; it gives me city null and every other option as null
does anyone have any suggestions on how to get the users IPV4 address through cloudflare and azure?
Or any suggestions on other ways to do this? It's prolonging the launch of my website.
I am pretty new to understand geo-location and ip addresses and all that, so please bare that in mind.
Thanks
The reason that you are getting IPV4 address from your home and IPv6 from somewhere else as by default, Cloudflare provides free IPv6 support to all domains without requiring additional configuration or hardware. If your origin web server is not compatible with IPv6, Cloudflare allows toggling IPv6 Compatibility to Off. You can disable the IPV6 Compatibility to Off from cloudflare.
Reference: https://support.cloudflare.com/hc/en-us/articles/229666767
Cloudflare put into this header whatever the connecting client IP is, so they really have little control over what the user-agent decides to do.
Also check if your network has ‘good’ IPv6 connectivity, or are you getting sub-optimal routing compared to IPv4.
Check this link for additional reference.
http://www.webhostingtalk.com/showthread.php?t=1692173

PHP malformed IP address and host. What is this?

I track downloads from my website by adding a database entry for each download that contains the IP address and host of the downloading person.
I use this PHP code to retrieve the IP address
isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]
and the host with the PHP function gethostbyaddr, passing the IP address.
This has been working perfectly fine for years, until something weird happened:
Today I saw two download entries for which both the IP address and host are 2a02:2028:1aa:2dc1:854e:9ccc:b423:7c93.
Domaintools says it's a "Malformed Domain or IP".
Could someone tell me what that thing is and why it's malformed?
I don't think it's a bot or something because my stuff can only be downloaded by real persons, so I'm really confused?!
It's not malformed.
It's an IPv6 address.
It's probably someone tunnelling or proxying from their IPv6 network into the IPv4 internet.
DomainTools doesn't seem to be IPv6 aware, or at least not the tool you used, but this one is.

error when i used my ip address instead of localhost as URL

I have downloaded WAMP server and i have written a very very simple php code and saved it in
C:\wamp\www\php_lear
folder. I have tested it using chrome giving url as
{localhost/php_lear/eg2.php}
And it worked fine. This uses a database stored in phpmyadmin. I found out my ip address from google 117.195.230.41. When i give
{117.195.230.41/php_lear/eg2.php}
as URL it gives me 404 not found
"The requested URL '/php_lear/eg2.php' was not found on this server"
Please help. I have no knowledge of ips and urls and very new to this field and yeah i have added this ip as allowed user in phpmyadmin. I actually want to use this in my android app.
The IP address you get from google is the IP address of your router. It does not point to your computer. As some ppl said, besides there is different ports to use in a connection and your WAMP installation is "listening" on the port 80 of your computer (127.0.0.1)
When you access to the 117.195.230.41 you are accessing to the IP that your Internet Service Provider gives to your installation. So you need to access your router and redirect all the querys to the 117.195.230.41 on port 80 to your port 80 and the IP of your computer in your local network.
The Public/Private IP confusion is a common misunderstanding.
Mike is correct. Due to how IP addressing works, there's a limited number of addresses. As a result, Network Address Translation was born (among other irrelevant things). The Public IP is what the world sees when it glances at your traffic. You want your Private IP, the one your router's DHCP has given you.
1) Open command prompt.
2) Issue the command "ipconfig" (without the quotes).
3) Find your "IPv4 Address". That's the one you want.
Additionally, follow Surt's suggestion to get everything working properly.

Categories