Welcome to Hiya Studio For Music Recordings And Website Design
admin

Php To The Rescue!

WordPress / Drag N Drop CMS editors can help even beginners create great sites for sure,  and with all the plugins available there is usually an ‘off the shelf’ solution for ‘advanced website features’, but sometimes a bit of good old fashion coding is needed.

 

(Php generates the HTML code dynamically at the server end, and has a huge library of functions that can do all sorts of things from database work to advanced string manipulation).

 

I needed a very simple thing to be done – place 3 images in the header, place a border them, highlighting the active one. 2 of the images linking the current page to the same page on 2 other subdomain sites.

 

(This was so that i could offer US UK And EU hosting in the respective currencies at the appropriate data centre locations).

You can see the php code in action by clicking the flags in the header of my hosting websites.

Code for hiyahosting.com

 

<?php

$eu = ‘https://eu.’.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];

$us = ‘https://us.’.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];

$gb = ‘https://’.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];

$styledark=” style=”.chr(34).”border:7px solid #5ca2bb”.chr(34);

$stylelight=” style=”.chr(34).”border:7px solid #d0f3ff”.chr(34);

$width=” width=”.chr(34).”45″.chr(34);

$str=chr(34).”https://hiyahosting.com/wp-content/uploads/2021/07/euflag1-e1627661909488-300×200.png”.chr(34);

$str2=chr(34).$eu.chr(34);

echo “<a href=”.$str2.chr(62);

echo “<img src=”.$str.$width.$styledark.chr(62);

echo “</a”.chr(62);

$str=chr(34).”https://hiyahosting.com/wp-content/uploads/2021/07/ukflag-e1627661965555-300×179.png”.chr(34);

$str2=chr(34).$gb.chr(34);

$width=” width=”.chr(34).”49″.chr(34);

echo “<a href=”.$str2.chr(62);

echo “<img src=”.$str.$width.$stylelight.chr(62);

echo “</a”.chr(62);

$str=chr(34).”https://hiyahosting.com/wp-content/uploads/2021/07/hkhosting1-e1627662055477-300×172.png”.chr(34);

$str2=chr(34).$us.chr(34);

$width=” width=”.chr(34).”50″.chr(34);

echo “<a href=”.$str2.chr(62);

echo “<img src=”.$str.$width.$styledark.chr(62);

echo “</a”.chr(62);

?>

 

The code for the subdomains was similar but the sub domain prefix needed stripping out using str_replace() to replace the prefix (eu. / us.) with a null replacement string.

 

 

Job done!

Cheers Tony

Leave a Reply