Relative Paths & Document Root

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

Post Reply
JeffS
Forum Newbie
Posts: 12
Joined: Thu Mar 06, 2003 8:05 pm

Relative Paths & Document Root

Post by JeffS »

Here's the issue.

All the pages on my website have a form. When a user clicks on "Submit" it sends them to another page. However, since these pages can reside either in the root directory or can be down a level or two in another subdirectory, the "action" part of the form has to have the path info.

I tried using getenv('DOCUMENT_ROOT') and then I'd concatenate the name of the file. While this works fine, however, if a user goes to view the source of the file they see a path something like "usr/etc/httpd/mydomain...../mysubdir/myfile.php"

The question is, how can I dynamically generate the proper path without showing the user the entire directory tree? OR, am I getting worried over nothing.

TIA for your help. Everyone here has been quite helpful.

Jeff
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

So where is the form relative to the script you want to send the data to? Is it always aimed at the same script? If so then why not make it point to http://www.yoursite.com/thetarget.php or something similar?
JeffS
Forum Newbie
Posts: 12
Joined: Thu Mar 06, 2003 8:05 pm

Yes...but...

Post by JeffS »

The only problem I see with that solution is that it is tied to a particular domain.

Thanks anyway for the suggestion.

Jeff
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Predefined Variables

Post by Kriek »

JeffS wrote:The only problem I see with that solution is that it is tied to a particular domain.
Use $SERVER_NAME

The name of the server host (domain) under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
JeffS
Forum Newbie
Posts: 12
Joined: Thu Mar 06, 2003 8:05 pm

Thanks!

Post by JeffS »

I'll give that a shot.

Jeff
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: Predefined Variables

Post by twigletmac »

Kriek wrote:Use$SERVER_NAME
$_SERVER['SERVER_NAME'] (for PHP version 4.1 or above) or $HTTP_SERVER_VARS['SERVER_NAME'] (for PHP version 4.0.6 or below) would be better.

Mac
JeffS
Forum Newbie
Posts: 12
Joined: Thu Mar 06, 2003 8:05 pm

Tried this -> $_SERVER['SERVER_NAME']

Post by JeffS »

I tested this:
<?php echo $_SERVER['SERVER_NAME'] ?>

and got this: 127.0.0.1

That's not right, is it?

Jeff
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

127.0.0.1 is the IP address for localhost so if you are running this on your local machine then it is a correct value.

Mac
JeffS
Forum Newbie
Posts: 12
Joined: Thu Mar 06, 2003 8:05 pm

Correct!

Post by JeffS »

That's what I thought. I just assumed that it would show me the IP address of the machine itself (which is completely different from the 127....).

Looks like this problem is solved!!

Thanks so much for your time and patience.

Jeff
Post Reply