$_server in php code example
Example 1: php server self
<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
<form action="">
Example 2: 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 3: php server
cd path/to/your/app
php -S 127.0.0.1:8000
Example 4: $_Server php
<?php
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo $_SERVER['HTTP_REFERER'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
?>
Example 5: phph get server protocol
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === 0 ? 'https://' : 'http://';
Example 6: 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>';
?>