tonbernradino Posted May 18, 2008 Share Posted May 18, 2008 Hi, I would like to ask how to do this: currently im working in my localhost if I access my localhost the directory in it are: clientname1 clientname2 now, my problem is im in localhost/clientname2 how to get the clientname2 only? $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; $URL= $protocol.'://'.$_SERVER['HTTP_HOST']."/"; this will display http://localhost/ but I want to include clientname2 $URL= $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; it will display http://localhost/clientname2/pages/product.php?page=about how to display this only http://localhost/clientname2/ Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/ Share on other sites More sharing options...
wildteen88 Posted May 18, 2008 Share Posted May 18, 2008 Use: $protocol = @$_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; $URL = $protocol.'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI']); Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/#findComment-544083 Share on other sites More sharing options...
tonbernradino Posted May 18, 2008 Author Share Posted May 18, 2008 when im in localhost/clientname2/pages/product.php it will display localhost/clientname2/pages/ Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/#findComment-544106 Share on other sites More sharing options...
phorman Posted May 18, 2008 Share Posted May 18, 2008 break the directory apart with something like explode, and look for the numbered occurance your interrested in. If its the directory thats one away from root then: <?php $directory = dirname($_SERVER["REQUEST_URI"]); $dir_array = explode("/",$directory); $lookingfor = $dir_array[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/#findComment-544119 Share on other sites More sharing options...
wildteen88 Posted May 18, 2008 Share Posted May 18, 2008 function getBaseDirURL() { $url = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) ? 'https://' : 'http://'; $url .= $_SERVER['HTTP_HOST']; $uri_path = pathinfo($_SERVER['REQUEST_URI'], PATHINFO_DIRNAME); // get the base directory $pos = strpos($uri_path, '/', 1); $url .= ($pos !== false) ? substr($uri_path, 0, ($pos+1)) : $uri_path; return $url; } echo getBaseDirURL(); Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/#findComment-544131 Share on other sites More sharing options...
tonbernradino Posted May 18, 2008 Author Share Posted May 18, 2008 thanks for all your help guys.. @phorman yeah it works but my problem is when im in this location http://localhost/clientname2/ it displays nothing. but when im in this location http://localhost/clientname2/pages/ it display clientname2 even im in this location http://localhost/clientname2/ or in this location http://localhost/clientname2/pages/ it should display clientname2 thanks guys.. Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/#findComment-544172 Share on other sites More sharing options...
wildteen88 Posted May 18, 2008 Share Posted May 18, 2008 did my suggestion work out? Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/#findComment-544329 Share on other sites More sharing options...
tonbernradino Posted May 18, 2008 Author Share Posted May 18, 2008 @wildteen88 yup.. thanks.. for got to update this thread. sorry.. Quote Link to comment https://forums.phpfreaks.com/topic/106142-solved-help-php-directory-handling/#findComment-544391 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.