Jump to content

Finding URL Path


Larry101

Recommended Posts

I am trying to find the URL to a directory TWO levels above the script level (if you know what I mean).

 

For example.. the script sits at

http://www.domain.com/TestArea2/members/index.php

BUT I need to find the path to 

http://www.domain.com/TestArea2/

 

the nearest I get is...


$domain = $_SERVER['HTTP_HOST'];
$domain .=  $_SERVER['REQUEST_URI'];
echo $domain; // outputs www.domain.com/TestArea2/members/index.php 

 

Is there a simple method to do this or have I got to split the string and work backwards?

 

Many thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/236416-finding-url-path/
Share on other sites

Tried all sorts but eventually wrote this... bit long winded but seems to work

 

$domain .=  $_SERVER['REQUEST_URI'];// $domain = /TestArea2/members/index.php

    $domain_arr = explode('/', $domain);
   
   $arr_len = count($domain_arr);//get length of array
   
   for ($i=1;$i<$arr_len-2;$i++){  //loop through except last 2
        $url_path .= "/" .$domain_arr[$i];
   }
   echo $_SERVER['HTTP_HOST'] .$url_path ."<br>"; //prints www.domain.com/TestArea2

Link to comment
https://forums.phpfreaks.com/topic/236416-finding-url-path/#findComment-1215499
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.