Skeleton directory part 2: PHP for dynamic content in new account default home page
Posted on 21 Jan 2011 by Alan Burns
This is a continuation from Skeleton directory part 1.
In my skeleton directory I placed a /public_html directory containing an index.php file. This ensures that a client’s brand new domain, or in fact any new cPanel account I create, immediately has a home page viewable by whoever seeks that domain in their web browser. I include a little PHP in the web page code, to customize the message to the particular domain.
My index.php file includes:
- Information on my hosting, and code to automatically display the new domain name with a message.
- Meta link to load my own central CSS file, hosted centrally, to provide design and formatting for the page consistent with that of own my web site.
- IMG reference to display the GIF of my company logo, which is hosted centrally.
To dynamically display the domain name used to reach the web page, the HTML BODY of my index.php file contains this PHP code:
$host = $_SERVER['SERVER_NAME'];
$host_domain = str_replace("www.", "", $host);
echo $host_domain;
?></h1>
<div>
<p>< ?
$host = $_SERVER['SERVER_NAME'];
$host_domain = str_replace("www.", "", $host);
echo $host_domain;
?> has not set up their web site yet.</p></div>
When served by the web server, that page will display the new domain name in large H1 heading type, and further down would say, for example: “bigfalafel.com has not set up their web site yet.”
To add a professional touch, I also use the following PHP code in the HTML HEAD:
<title>< ?
$host = $_SERVER['SERVER_NAME'];
$host_domain = str_replace("www.", "", $host);
echo $host_domain;
?> </title></head>
That code dynamically displays the new domain name in the title bar of the browser. The bit about str_replace(“www.” strips away the “www.” if a visitor prepended that to the domain name when navigating to the site. Personally, I prefer the look of a domain name without the overused “www.”, but of course you could remove that string if you don’t agree.
PHP is a powerful web language. With a little imagination and some skill, one could go far beyond what I have done to display all manner of dynamic content. The beauty of cPanel/WHM’s skeleton directory is that you set it up once, and it applies to every new cPanel account that you create.
How to prevent directory indexing
04 Feb 2011 by Alan Burns