Answers for "php server ip"

PHP
2

php ip

// Function to get the client IP address
function get_client_ip() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
       $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
Posted by: Guest on August-10-2020
1

php server function

<?php
  // PHP $_SERVER['...']; method
  
  // PHP file name
  echo 'PHP file name: '.$_SERVER['PHP_SELF'].'<br>';
  // Server name
  echo 'Server name: '.$_SERVER['SERVER_NAME'].'<br>';
  // HTTP host
  echo 'HTTP host: '.$_SERVER['HTTP_HOST'].'<br>';
  // Refering link
  echo 'Refering link: '.$_SERVER['HTTP_REFERER'].'<br>';
  // User agent
  echo 'User agent: '.$_SERVER['HTTP_USER_AGENT'].'<br>';
  // Script name
  echo 'Script name: '.$_SERVER['SCRIPT_NAME'];
  
  // The rest is optional

  if($_SERVER['PHP_SELF']=='/filename.php'){
    //If there is no folder
    echo 'No folder'.$_SERVER['PHP_SELF'];
  } else{
    // Echo the name of the folder containing the PHP file
    echo 'PHP file name: '.$_SERVER['PHP_SELF'];
  }
  
  // The same if statements can be used for the script name
  
  if($_SERVER['SCRIPT_NAME']=='/filename.php'){
    // If there is no folder
    echo 'No folder'.$_SERVER['SCRIPT_NAME'];
  } else{
    // Echo the name of the folder containing the PHP file
    echo 'PHP file name: '.$_SERVER['SCRIPT_NAME'];
  }
  
  echo '<a href="repl.it/@CoolWebDev">More from me...</a>';
  
  // I hope you found this helpful! 
?>
Posted by: Guest on July-06-2020
0

get server ip php

$exec = 'ipconfig | findstr /R /C:"IPv4.*"';
exec($exec, $output);
preg_match('/\d+\.\d+\.\d+\.\d+/', $output[0], $matches);
print_r($matches[0]);
Posted by: Guest on February-16-2021

Browse Popular Code Answers by Language