Home >php教程 >php手册 >获取当前服务器地址

获取当前服务器地址

WBOY
WBOYOriginal
2016-06-06 19:35:50870browse

获取当期的服务器地址 无 ?php $addr = my_ip(); echo "my ip address is $addr\n"; function my_ip($dest='64.0.0.0', $port=80) { $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_connect($socket, $dest, $port); socket_getsockname($so

获取当期的服务器地址
<?php 
  $addr = my_ip();
  echo "my ip address is $addr\n";

  function my_ip($dest='64.0.0.0', $port=80)
  {
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_connect($socket, $dest, $port);
    socket_getsockname($socket, $addr, $port);
    socket_close($socket);
    return $addr;
  }

?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn