Greetings All!

I currently have a particular PHP script that I keep in three different "environments": production, demo, and test.

Up until now, I've been rather careful about constructing the script so that I can just copy it over from one environment to another and just alter ONE variable ($demo) to flip on or off when I move it.

But today, I added some functionality for the script to write some files to a subdirectory underneath it. After writing the files, the script also prints a link within the browser for the downloading of each file.

So far, in "test", I've been using exact directory pathnames and exact URL's to refer to the directory that the files are placed in. What I'd LIKE to do is have both the pathnames and the URL's dynamically generated without me having to hard-code the base path or base URL into the script.

I think I've accomplished this for the pathname. I have the script do a "$curdir = getcwd();" to get the current path we are in and then I refer to the subdirectory off of this. (However, I admit that I'm not sure that that the current working directory will always pull up as the directory the script itself is executing in? I also have a feeling this is a security risk.)

But I have no idea what to do with the URL. I thought I could use $HTTP_REFERER, but it looks like this has been disabled, as it just gives me the domain name for the site.

Can anybody tell me how I might dynamically generate both the path and the URL to the directory that my script is executing in?

Thanks!

-= Dave =-

    Use this:

    "http://".$SERVER['HTTP_HOST'].dirname($SERVER['SCRIPT_NAME'])

    That will return the domain and directory of the current script, so all you need to do is put "/something.html" on the end of it. Easy 🙂

      Write a Reply...