| Server Variable Host Name In php |
Server variable host name in php programming language. We are going to get server environmental information.
$_SERVER Variable Host name (Screenshot1)
Code for $_SERVER variable Host Name
1
2
3
4
5
| <?phpecho $_SERVER['HTTP_HOST'];?> |
Output (Screenshot2):-
$_SERVER Variable Host name (Screenshot2)
$_SERVER variable can also return host name like http://extratutorials.com Domain name now here i am working withlocalhost so its just echo out for the localhost because i am running with local server With help of key HTTP_HOST.
Code for $_SERVER Variable Host name
conf.inc.php(Screenshot3):-
$_SERVER Variable Host name (Screenshot3)
1
2
3
4
5
6
| <?php$host = $_SERVER['HTTP_HOST']; $images = $host.'/images/';?> |
index.php (Screenshot4):-
$_SERVER Variable Host name (Screenshot4)
1
2
3
4
5
6
| <?php require 'Conf.ini.php';echo '<img src="'.$images.'header.gif" />';?> |
This Short of code is example for generate dynamically of host name with help of $_SERVER variable which is already predefined in php programming language. As You can see we had two files such as conf.inc.php which contains Dynamic generating host name with help of key such as HTTP_HOST and then with help of this variable $host which is generated dynamically domain name we have images folder for example which contains header.gif image in it.
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.
Read More Extra Tutorials
Read More Extra Tutorials
No comments:
Post a Comment