What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » get URI folder for executing PHP script

get URI folder for executing PHP script
Author: Message:
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
Joined: Nov 2004
Status: Away
O.P. get URI folder for executing PHP script
basically, I am looking for a method to obtain the directory where the current script is running. I do know that $_SERVER['REQUEST_URI'] contains the full url, but it is not cross platform. (*cough* IIS *cough*)

so for any url, http://subdomain.domain.tld/folder/folder2/file.php, i need http://subdomain.domain.tld/folder/folder2/ to be returned

help please? anyone?
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
08-28-2007 11:49 PM
Profile PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: get URI folder for executing PHP script
quote:
Originally posted by MeEtc
I do know that $_SERVER['REQUEST_URI'] contains the full url, but it is not cross platform. (*cough* IIS *cough*)
Code stolen from WordPress... :tongue:
code:
// Fix for IIS, which doesn't set REQUEST_URI
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?

    // Append the query string if it exists and isn't null
    if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
        $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    }
}
REQUEST_URI won't contain the hostname though... you can get that from HTTP_HOST.
08-29-2007 12:27 AM
Profile PM Web Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
Joined: Nov 2004
Status: Away
O.P. RE: get URI folder for executing PHP script
oops, did i say REQUEST_URI? i meant SCRIPT_URI...
Thanks DZ, but that still doesn't take out the file name...
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
08-29-2007 12:37 AM
Profile PM Web Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: get URI folder for executing PHP script
stolen from php.net :cheesy:

code:
<?php

$path_only = implode("/", (explode('/', $_SERVER["SCRIPT_URI"], -1)));

print $path_only;

?>


This post was edited on 08-29-2007 at 12:50 AM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
08-29-2007 12:40 AM
Profile PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: get URI folder for executing PHP script
SCRIPT_URI? I've never seen that used in PHP... :-/ (Edit: Apparently it only exists under Apache with mod_rewrite enabled)

Anyway, the easiest way to remove the filename is to use the dirname() function... :p

code:
if(empty($_SERVER['REQUEST_URI'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
}

// Strip off query string so dirname() doesn't get confused
$url = preg_replace('/\?.*$/', '', $_SERVER['REQUEST_URI']);
$url = 'http://'.$_SERVER['HTTP_HOST'].'/'.ltrim(dirname($url), '/').'/';
http://shoutbox.menthix.net/crap/asdf/uri_test.php :spam:

This post was edited on 08-29-2007 at 01:19 AM by WDZ.
08-29-2007 12:58 AM
Profile PM Web Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
Joined: Nov 2004
Status: Away
O.P. RE: get URI folder for executing PHP script
code:
echo(implode("/", (explode('/', $_SERVER["SCRIPT_URI"], -1))).'/');
thanks rofl

This post was edited on 08-29-2007 at 02:42 AM by MeEtc.
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
08-29-2007 02:41 AM
Profile PM Web Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: get URI folder for executing PHP script
quote:
Originally posted by WDZ
http://shoutbox.menthix.net/crap/asdf/uri_test.php :spam:
[offtopic/]
lol @ /crap/asdf
[quote]
Ultimatess6
: What a noob mod
08-29-2007 03:27 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On