get url  (including subdomain)

Posted on 2011-05-07
Last Modified: 2012-05-11
want the entire page url, including subdomain

I would like (if possible)
subdomain to be $variable1
domain to be $variable2
uri to be $variable3
Question by:rgb192
    LVL 15

    Expert Comment

    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.
    LVL 12

    Accepted Solution

    Of course possible!
    $domainArray = explode('.', $_SERVER["SERVER_NAME"]);
    $variable1 = $domainArray[0];
    $variable2 = $domainArray[1] . '.' . $domainArray[2];
    $variable3 = $_SERVER['REQUEST_URI'];

    Open in new window

    LVL 107

    Expert Comment

    by:Ray Paseur
    I generally agree with Medo3777, however the URL might be something like 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.

    Author Closing Comment

    i will have to open a question about a complex url that Ray suggested

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now