简体   繁体   中英

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM