server host in php code example
Example 1: php server name
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
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>';
?>