$_Server variable host name in php programming language. We are going to get server environmental information.
Code for $_SERVER variable Host Name (Screenshot1):-
Code $_SERVER Variable Host Name Screenshot1 |
<?php echo $_SERVER['HTTP_HOST']; ?>
Output (Screenshot2):-
Screenshot2 |
$_SERVER variable can also return host name like http://www.google.com Domain name now here i am working with localhost so its just echo out for the localhost because i am runing with local server With help of key HTTP_HOST.
Code for $_SERVER Variable Host name
conf.inc.php(Screenshot3):-
Screenshot3 |
<?php $host = $_SERVER['HTTP_HOST']; $images = $host.'/images/'; ?>
index.php (Screenshot4):-
Screenshot4 |
<?php require 'Conf.ini.php'; echo '<img src="'.$images.'header.gif" />'; ?>
Index.php page had require function which we already had article on it. returns image on index.php page. with particular domain name file is uploaded which is dynamically generated.
Now you may be thinking how this example will help us. So, if you are shifting your files to another domain or hosting for example we are on localhost now we want to shift to hosting with particular domain name it makes easy there are other methods and technique to do so. But this small example to you people know uses about $_SERVER variable Host name with key HTTP_HOST. It will automatically generate directory of hosting. Its helps us to transferable project or website easily.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..