Page 1 of 1

Relative Paths & Document Root

Posted: Mon Mar 17, 2003 8:27 am
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

Posted: Mon Mar 17, 2003 10:26 am
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?

Yes...but...

Posted: Wed Mar 19, 2003 2:19 pm
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

Predefined Variables

Posted: Wed Mar 19, 2003 2:36 pm
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.

Thanks!

Posted: Wed Mar 19, 2003 3:13 pm
by JeffS
I'll give that a shot.

Jeff

Re: Predefined Variables

Posted: Thu Mar 20, 2003 2:26 am
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

Tried this -> $_SERVER['SERVER_NAME']

Posted: Thu Mar 20, 2003 6:20 am
by JeffS
I tested this:
<?php echo $_SERVER['SERVER_NAME'] ?>

and got this: 127.0.0.1

That's not right, is it?

Jeff

Posted: Thu Mar 20, 2003 6:48 am
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

Correct!

Posted: Thu Mar 20, 2003 6:55 am
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