mohamed shubber
mohamed shubber

Reputation: 143

How to obtain my PC lan card's IP address in PHP

I use the code below to display my IP and it is working just fine `

$host= gethostname();
$MyIp= gethostbyname($host);
echo $MyIp;

But my problem is that when both Lan and WiFi are connected, the code fetch the WiFi IP not the lan's. How to direct the code the the lan only?

Upvotes: 1

Views: 233

Answers (1)

Vidal
Vidal

Reputation: 2606

To get the ip address you can use $_SERVER['REMOTE_ADDR']; this will get you the ip address that was used when the request was made.

PHP can't get you both ip addresses it will get you only the ip that was use when the request was made. The decision on which ip is used is based on your computer, it decides which one to use base on speed, connection or ip address(same network).

Upvotes: 1

Related Questions