This article mainly introduces the use of dos
command to obtain the IP
address, and also provides the use of php
to obtain ip
Address method.
As we all know, when a computer queries the local IP address, it usually uses the dos
command
win r
call outdos
Command
Use ipconfig/all
to get your ip
address (I will not expose my IP)
But how to get your IP
address in php
?
Method one:
<?php $ip = $_SERVER["REMOTE_ADDR"]; echo $ip; ?>
Method two:
<?php $ip = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]; $ip = ($ip) ? $ip : $_SERVER["REMOTE_ADDR"]; echo $ip; ?>
Method three:
<?php if(getenv('HTTP_CLIENT_IP')) { $onlineip = getenv('HTTP_CLIENT_IP');} elseif(getenv('HTTP_X_FORWARDED_FOR')) { $onlineip = getenv('HTTP_X_FORWARDED_FOR');} elseif(getenv('REMOTE_ADDR')) { $onlineip = getenv('REMOTE_ADDR');} else { $onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];}echo $onlineip; ?>
Recommended: "php video tutorial" "php tutorial"
The above is the detailed content of How to get ip address using php. For more information, please follow other related articles on the PHP Chinese website!