PHP function to get the subdomain of a URL

Here’s a one line solution: array_shift((explode(‘.’, $_SERVER[‘HTTP_HOST’]))); Or using your example: array_shift((explode(‘.’, ‘en.example.com’))); EDIT: Fixed “only variables should be passed by reference” by adding double parenthesis. EDIT 2: Starting from PHP 5.4 you can simply do: explode(‘.’, ‘en.example.com’)[0];

Subdomain on different host [closed]

A sub domain is part of the domain, it’s like subletting a room of an apartment. A records has to be setup on the DNS for the domain e.g mydomain.example has IP 123.456.789.999 and hosted with Godaddy. Now to get the sub domain anothersite.mydomain.example of which the site is actually on another server then login … Read more

When should one use a ‘www’ subdomain?

There are a ton of good reasons to include it, the best of which is here: Yahoo Performance Best Practices Due to the dot rule with cookies, if you don’t have the ‘www.’ then you can’t set two-dot cookies or cross-subdomain cookies a la *.example.com. There are two pertinent impacts. First it means that any … Read more

“Could not get any response” response when using postman with subdomain

First Go to Settings in Postman: Off the SSL certificate verification in General Tab: Off the Global Proxy Configuration and Use System Proxy in Proxy Tab: Make Request Timeout to 0 (Zero) Configure Apache: If the above changes resulted in a 404 response, then continue reading 😉 Users that host their site locally (like with … Read more

Share cookie between subdomain and domain

If you set a cookie like this: Set-Cookie: name=value then the cookie will only apply to the request domain, and will only be sent for requests to the exact same domain, not any other subdomains. (See What is a host only cookie?) Two different domains (e.g. example.com and subdomain.example.com, or sub1.example.com and sub2.example.com) can only … Read more