/    Sign up×
Community /Pin to ProfileBookmark

PHP: Fetching foldername from URL

Hi,

I came up with this problem last night.

I have a URL [url]http://www.mysite.com[/url]

How do I fetch the folder name that was supplied in the URL.

For example:

[url]http://www.mysite.com/xyz[/url]
or
[url]http://mysite.com/myfolder[/url]
or
[url]http://www.mysite.com/xxx[/url]

Please note that I can either use www or [url]http://www[/url] or just http:// in my domain name but I need to fetch the folder name that was supplied in the URL.

PS:

I tried the following code, but it didnt revealed the foldername supplied

[code]<?php
echo $_SERVER[‘HTTP_HOST’];
?>
[/code]

Please help.

Thanx

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@tfk11Mar 16.2008 — You can use $_SERVER['php_self'] to get the path to the script and the pathinfo() function can extract the the directory name.

For future reference the phpinfo() function shows you the values of all the php variables.
×

Success!

Help @phantom007 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...