0

I have an unusual situation where I have a link from my site

site.co.uk through to my ecommerce cart sitecouk.ecommercesite.com and I am setting up a second US site which I want to have as site.us through to my ecommerce cart siteus.ecommercesite.com

because site.co.uk becomes sitecouk in the cart and site.us becomes siteus, I would have to have the link pull the domain from the URL and stip the dots (periods) in my html link,

this will be the final straw in allowing me to have identical source HTML / PHP codes for both stores.

The final link would look something like

<a href="https://<?=$variable?>.ecommercesite.com/cart?cart=view" title="Cart">View Cart</a>

where

$variable = my stripped domain name (e.g sitecouk)

therefore the resulting link would be

<a href="https://sitecouk.ecommercesite.com/cart?cart=view" title="Cart">View Cart</a>

any thoughts on how to get a stripped domain name from the current URL of the page?

Thanks

Henry

Henry Aspden
  • 1,863
  • 3
  • 23
  • 45

1 Answers1

1

You should be able to either use the Host Header value:

str_replace('.','',$_SERVER['HTTP_HOST'])

or the Server Name value:

str_replace('.','',$_SERVER['SERVER_NAME'])

Depending on your environment configuration.

Note that HTTP_HOST may contain versions with or without www. and sometimes port numbers if not 80, but SERVER_NAME should be more consistent as it's what you've defined within your webserver configuration. For clarification see this question/answer.

Scuzzy
  • 12,186
  • 1
  • 46
  • 46