0

i m sorry im newbie here,.. so i want to ask about, how to get the IP from the server,. . first i user PEAR2 to get an api from Mikrotik, then i want to get an IP for making a log, to log what an IP that Connect or Dissconnect from the network itself... the reason why i make the log from PEAR2, i want to make a notification android based, that if the client from the mikrotik's is disconnect or connect, it will send a notif to an android apps.. . in those case PHP i use this script,

                          echo $server_ip = gethostbyname($_SERVER['SERVER_NAME']);
                    ?>  is this a correct..? 

. many thanks for you all. im sorry for My bad English

enter image description here

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Possible duplicate of [How to identify server IP address in PHP](https://stackoverflow.com/questions/5800927/how-to-identify-server-ip-address-in-php) – Thamaraiselvam Jul 31 '17 at 09:08

2 Answers2

0

You want echo $server_ip = $_SERVER['SERVER_ADDR'] What you have gives you the host name.

Difster
  • 3,264
  • 2
  • 22
  • 32
0

Like this for the server ip: If you mean getting the user's IP address, you can do something like :

<?php
    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else{
      $ip=$_SERVER['REMOTE_ADDR'];
    }
?>

<?php echo  "<br />".$ip;?>
Anand Pandey
  • 2,025
  • 3
  • 20
  • 39