php server ip code example
Example 1: php ip
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;
}
Example 2: php server function
<?php
echo 'PHP file name: '.$_SERVER['PHP_SELF'].'<br>';
echo 'Server name: '.$_SERVER['SERVER_NAME'].'<br>';
echo 'HTTP host: '.$_SERVER['HTTP_HOST'].'<br>';
echo 'Refering link: '.$_SERVER['HTTP_REFERER'].'<br>';
echo 'User agent: '.$_SERVER['HTTP_USER_AGENT'].'<br>';
echo 'Script name: '.$_SERVER['SCRIPT_NAME'];
if($_SERVER['PHP_SELF']=='/filename.php'){
echo 'No folder'.$_SERVER['PHP_SELF'];
} else{
echo 'PHP file name: '.$_SERVER['PHP_SELF'];
}
if($_SERVER['SCRIPT_NAME']=='/filename.php'){
echo 'No folder'.$_SERVER['SCRIPT_NAME'];
} else{
echo 'PHP file name: '.$_SERVER['SCRIPT_NAME'];
}
echo '<a href="repl.it/@CoolWebDev">More from me...</a>';
?>
Example 3: 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]);