Tuesday 18 March 2014

SERVER Variable Host name


global variables in php
$_Server variable host name in php programming language. We are going to get server environmental information.

Code for $_SERVER variable Host Name (Screenshot1):-

Server variable Host Name php
Code $_SERVER Variable Host Name Screenshot1

<?php



echo $_SERVER['HTTP_HOST'];



?>

Output (Screenshot2):-

global variables in php
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):-

server variables Host name php
Screenshot3

<?php



$host = $_SERVER['HTTP_HOST'];

$images = $host.'/images/';



?>

index.php (Screenshot4):-


server variable Host name php
Screenshot4

<?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.



No comments:

Post a Comment

Thanks For Comment Will get you Soon..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates