I serve my PHP script with port forwarding(i use mamp) other users can view website but php don't return true client ip, it always return my server ip. I can't find my vpn ip in $_SERVER array what is problem? thanks.
To obtain ip address of clients from the server use $_SERVER['REMOTE_ADDR'].
And to do it on client side using javascript and ajax for retrieving and sending ip address. see this link http://jsonip.com/
Related
So why am I need my own ip by using get content? I want to use some tv channels which is m3u8 file and using m3u8?wmsAuthSign=code
wmsAuthSign code is changing everytime the page refresh it self and they are getting ip adrress inside of that code.
So i can't play the tv channel by my servers ip !
the code i gave down below is just an example :D
<?php
$myURL = "https://whatismyipaddress.com/ip-lookup";
$lines = file($myURL);
echo $lines[145];
?>
Is there any way that i can change it to my one ip adresse?
If you mean the client (browsers) IP:
That code is being executed on your server, so the machine fetching that URL is your server. The response then has your server's IP address.
If you want to get the IP address of the user that's accessing the server, you could use some of the $_SERVER variables (like $_SERVER['REMOTE_ADDR']) but due to the way the internet works, that may not be the user's IP address.
Your best bet there is to use javascript that runs on the user's browser to identify the user's IP address - though, since that is really under the user's control, you can't be certain it's accurate either.
If you mean you're getting the IP of a different server, not your web server: the method you're using only determines the IP address of the server acting as a gateway to the greater internet. If your web server is behind a firewall, you'll be getting the IP of the firewall. You may want to identify the web server's local IP address instead.
Because the server is executing the PHP code and is requesting the website, if you want to get the IP address of the current user see How to get the client IP address in PHP?
I have one load balancer and three EC2 web servers with Linux and Apache. Whenever I use $_SERVER['REMOTE_ADDR'] in PHP to take website's visitor's IP addresses, It shows me a wrong IP address. When I check the IP in Whois databases then I will find its a reserved IP. I guess its IP of another server in AWS itself instead of client's IP. How Can I get correct client's IP with PHP in EC2 servers?
The IP is a local Amazon IP because the visitors does not connect to your server directly.
Normally the Load balancer forwards the real client IP in the $_SERVER array under a new key, in most cases $_SERVER['HTTP_X_FORWARDED_FOR']
What the cURL sends to the request's address? The PHP script is hosted on a dedicated server. When I'm accessing the script, is it sending my IP address or the server's one with a referer? I was always wondering this.
Since the PHP server is making the request, it is sending its own IP address.
I have a server connected to the internet through a Fortigate 40C. When my php code calls $_SERVER['REMOTE_ADDR'], it returns the ip address of the router (the fortigate) rather than the remote IP accessing the php script.
Why is this?
The Fortigate has an option to "enable NAT" on a policy, which doesn't mean translate the addresses (it does that for you anyway), but does mean it alters some packets replacing the remote IP with the gateway IP.
Make sure that "Enable NAT" is disabled, and $_SERVER['REMOTE_ADDR'] will work as expected.
There are 2 servers A and B. I have my php script in server B.
Now, the client sends some data to server A and server A sends it to server B.
I want to get the IP address on which the request came(that is server A). How can I do it using php?
If I use $_SERVER['REMOTE_ADDR'], I get the clients IP address.
If I use $_SERVER['SERVER_ADDR'], I get the null value.
$_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] should return the DNS name of the server. If you can use the DNS instead of the IP I think maybe you should try with one of these variables. Although, as mentioned earlier, if $_SERVER['SERVER_ADDR'] isnĀ“t populated you probably have a faulty configuration.
Provide information about server, IIS/Apache, OS, PHP version, it might be easier to help.
Also, try echoing/logging $_SERVER['SERVER_ADDR'] on server A where the request comes in and see if you get a value from there because reading $_SERVER['SERVER_ADDR'] on server B should give you IP of server B. If you get a value on server A you can save/pass the value forward to server B in code (wherever your transaction from server A to B takes place).
"The IP address of the server under which the current script is executing."