Get Site Root

Discussion in 'PHP' started by Silver89, Oct 10, 2009.

  1. #1
    I'm creating a link echange script for one of my sites, when validating the link has been placed on their site I want to check the hompage/root of the site for a link.

    If they give me a url such as: http://mysite.com/abc/ssds/page.php


    Is there anyway in php to just get the root: http://mysite.com/

    Without using a stripping function?

    Thanks
     
    Silver89, Oct 10, 2009 IP
    sachin410 likes this.
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    $url = "http://mysite.com/abc/ssds/page.php";
    $n = parse_url($url);
    echo $n['host'];
     
    php-lover, Oct 10, 2009 IP
    Silver89 likes this.
  3. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #3
    Thanks that's perfect!
     
    Silver89, Oct 10, 2009 IP