Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4565402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:38:17+00:00 2026-05-21T18:38:17+00:00

With php, I want to return the current url of the page I am

  • 0

With php, I want to return the current url of the page I am currently on.

for example, if this script is run on http://www.google.com, I want to echo out ‘google’ sans http://

OR

if this script is run on http://173.244.195.179, I want to echo out ‘173.244.195.179’ sans http://

I’ve looked at $_SERVER but haven’t been able to get it to work. Suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T18:38:18+00:00Added an answer on May 21, 2026 at 6:38 pm
    $domain = $_SERVER['HTTP_HOST'];
    $ar = explode('.', $domain);
    
    echo $ar[0];
    

    Maybe?

    EDIT: (Supports subdomains)

    function domain()
    {
        $ends = array('net','com','info','org');
    
        $domain = $_SERVER['HTTP_HOST'];
        $ar = explode('.', $domain);
    
        $result = '';
    
        $i = 0;
        $found = false;
        for($i; $i<sizeof($ar); $i++)
        {
            $j = 0;
            for($j; $j<sizeof($ends); $j++)
            {
                if($ends[$j] == $ar[$i]) $found = true;
            }
    
            if($found) break;
            $result .= $ar[$i] . '.';
        }
    
        return substr($result, 0, strlen($result)-1);
    }
    
    echo domain();
    

    I’m going to put my money on that there’s a way simpler or inbuilt way of doing this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have placed a php code for getting current page URL and now I
I am working with php and want to have a page that has a
I have this string in php i want to skip the ppattern ------------------------------------------ FROM:Andy;
Somebody told me that example.com/en is more friendly than example.com/index.php?lang=en . How can I
How to do a doOnce function? I have this jQuery script and I want
OK, i'm creating a small PHP application. The current structure is something like this:
<?php /**************************************************************************** * paging.class.php v 1.0 * * version 1.0 * * This script
This is my first attempt at a php script after a few weeks of
I have a php file that returns a div and a javascript. I want
basically I want php to decide which version of the site pieces to load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.