• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

get url (including subdomain)

want the entire page url, including subdomain

I would like (if possible)
subdomain to be $variable1
domain to be $variable2
uri to be $variable3
1 Solution
you have a string with the whole URL on the variable:


then you can split string by using php functions to get different parts of string. Functions like strpos to get the position of a character inside an string, or functions like substr to get a part of the string.

Here you have the list of all string functions:

Hope it helps.
Mohamed AbowardaSoftware EngineerCommented:
Of course possible!
$domainArray = explode('.', $_SERVER["SERVER_NAME"]);
$variable1 = $domainArray[0];
$variable2 = $domainArray[1] . '.' . $domainArray[2];
$variable3 = $_SERVER['REQUEST_URI'];

Open in new window

Ray PaseurCommented:
I generally agree with Medo3777, however the URL might be something like www.atf77.whitehouse.gov/csm/index.php?q=foo.bar so you might want to learn about the PHP functions that parse strings and parse urls.  Google those terms and you will find a wealth of generalized solutions for parsing this sort of information.
rgb192Author Commented:
i will have to open a question about a complex url that Ray suggested

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now