Stripping URL information into variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
SFADuncan
Forum Newbie
Posts: 23
Joined: Mon Aug 11, 2003 5:06 pm
Location: uk

Post by SFADuncan »

Thanks... I appreciate your help... I thought I was clear, but apologise for any confusion caused. Very grateful.
Post Reply