Page 2 of 2
Posted: Tue Jun 08, 2004 12:38 pm
by Weirdan
Grim... wrote:jason wrote:I am sorry, but if you are going to ask the question, ask the right question.
To be fair, he did ask the right question.
He said:
SFADuncan wrote:I'm trying to isolate the directory path of the url of a current page
getcwd() is one way of achieving this.
[php_man]getcwd[/php_man] returns current working directory. In a most cases your solution would work, but technicaly speaking it's not correct, as requested url does not always correspond to filesystem paths. Moreover, current working directory might be different from the directory containing your script.
Posted: Tue Jun 08, 2004 10:07 pm
by redmonkey
I've never had a problem with getcwd (although I haven't used that much). The only possible problem that springs to mind is if the getcwd is contained within an included file from a different directory you may get unexpected results.
Or you are running the CLI version of PHP in which case getcwd does not return the current working directory of the script (or at least that was the behaviour the last time I checked).
launchcode wrote:
What the hell? Why mess with cwd? To get the "full" URL of the current page on your site, just combine two values:
$_SERVER['HTTP_HOST'] and either $_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'] if you need all the query string values.
Merge the two and kick the result to parse_url.
Perhaps I picked this thread up wrong, but I did not think that the original poster was asking how to obtain the full url or any query strings.
Posted: Tue Jun 08, 2004 10:26 pm
by Weirdan
redmonkey wrote:The only possible problem that springs to mind is if the getcwd is contained within an included file from a different directory you may get unexpected results.
Consider the following httpd.conf fragment:
Code: Select all
#.....
Alias /somedir/ /local/path/to/someotherdir/
#.....
with that configuration getcwd would give you /local/path/to/someotherdir/ when user requests /somedir/somefile.php
Posted: Tue Jun 08, 2004 10:37 pm
by redmonkey
Weirdan,
Very true. Probably not too comon, but you would also think that the user would be aware of their file structure. Or at least they may notice this sort of thing when working with their FTP client.
Posted: Tue Jun 15, 2004 5:33 am
by SFADuncan
Thanks... I appreciate your help... I thought I was clear, but apologise for any confusion caused. Very grateful.