Click to See Complete Forum and Search --> : how can i find the absolute path from a script?


OM2
05-23-2007, 03:37 PM
is it possible for a script to give it's absolute path?
i want to put a script somewhere and be able for it to reports its own absolute path.

thanks.


om

Crucial
05-23-2007, 05:37 PM
Try _SERVER["PATH_TRANSLATED"]

You could also run php_info(); and review the PHP Variables section.

NogDog
05-23-2007, 05:55 PM
You can use the "magic" constant __FILE__ (note that it both begins and ends with double underscores).

OM2
05-23-2007, 06:57 PM
sorry, you misunderstand what i want.
i want the internet web address.

so if a file sits in: http://www.mydomain/dir1/subdir

this is exactly what i want: http://www.mydomain/dir1/subdir
(it doesn't matter if i get back an ip number, as long as i can identify the exact directory with path.)

also... i tried: <?php echo _SERVER["PATH_TRANSLATED"] ?>

this didn't work.
(i'm a newbie to php... have i typed it correctly above?)

Sheldon
05-23-2007, 07:07 PM
try this (Notice the $)

<?php
$path = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
echo($path);
?>

OM2
05-23-2007, 08:06 PM
brilliant.
nearly what i wanted. :D
i wanted just the path without the calling filename itself.

i'm sure i can string manipulate to get rid of the filename...
but is there a better way?
thanks.

NogDog
05-23-2007, 08:30 PM
$path = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

OM2
05-23-2007, 08:44 PM
Thank You!
:)