PDA

View Full Version : script location


misterx
01-12-2003, 01:36 AM
Is there a function in PHP that will return a script's location? I don't mean on the server either because that wouldn't really help me but if I could get something like http://www.maniacalmonkey.com/new/script.php that would rock.

If you know of some way to do this let me know. Thanks.

Xphp->UG-S<-
01-12-2003, 01:49 AM
what exactly do you mean?

can you explain a little more?

misterx
01-12-2003, 01:59 AM
Originally posted by Xphp->UG-S<-
what exactly do you mean?

can you explain a little more?

Ok, lets say there is a script located in a particular directory on my site. I probably know where it is because I put it there. But lets say I'm making something that I want other people to be able to use. If they upload the script to their server, I want a way to display that location, no matter where it is.

So if they upload it to domain.com/randomdirectoryname,
I want the script to be able to say, "The URL of this script is http://www.domain.com/randomdirectoryname/script.php"

firepages
01-12-2003, 02:28 AM
<?=$_SERVER['SCRIPT_FILENAME'];?>

misterx
01-12-2003, 02:54 AM
Ok, now that gave me the unix directory location (/home/user/webs/www.domain.com/directory/script.php)

But is there anything that will simply give me http://www.domain.com/directory/script.php ?

Nevermind....I think I found what I'm asking here:
http://www.php.net/manual/en/reserved.variables.php

misterx
01-12-2003, 03:18 AM
Ok so I ended up doing this:

$domain = $_SERVER['SERVER_NAME'];
$directory = $_SERVER['SCRIPT_NAME'];
print("http://".$domain.$directory);
Which gave me the URL of the script.

Now I'm wondering if there is a way I can do this to list the location of a script OTHER than the one that is currently running. Any ideas?