--

php question

is there some sort of function or global variable that I can call from within an included file to tell what file it was included IN?

Either that, or some way of accessing the full URI that user entered into their client for the current request. (rather than just the query string)
Permalink muppet 
March 4th, 2005
$_SERVER['REQUEST_URI']

array get_included_files()
Permalink haha 
March 4th, 2005
whoops. you want the file that did the including.
Permalink haha 
March 4th, 2005
debug_backtrace() will get you the file you are included in.
(assuming a recent enough PHP to have debug_backtrace())
Permalink Almost Anonymous 
March 4th, 2005
I'm using 4.2.x

guess that should have been part of the question
Permalink muppet 
March 4th, 2005
You poor bastard! Well then you are out of luck. You might want to consider upgrading to a version that isn't at least 3 years old (4.3.0 came out in December of 2002!)

If don't control the hosting make some vague mention of security flaws to them. ;)
Permalink Almost Anonymous 
March 4th, 2005
Oops, I was wrong. We've since upgraded to 4.3.10

I think I could compile 5 on the host myself, if I wanted to take the leap.

I have just about zero Linux compilation experience, though.
Permalink muppet 
March 4th, 2005
"Oops, I was wrong. We've since upgraded to 4.3.10"

Well then, you are in luck.

"I think I could compile 5 on the host myself, if I wanted to take the leap. I have just about zero Linux compilation experience, though."

I've done this -- although I recommend having your own Linux machine to play around with before attempting it on a production server. It took me a while to figure everything with compiling PHP (I had about zero Linux compilation experiece then). Now, many years later, I run my own custom compiled Linux kernel but I nearly always install PHP from recompiled packages (since they now exist).

PHP5 is great -- I've been doing a lot of development in it lately and it's hard to imagine life without it.
Permalink Almost Anonymous 
March 4th, 2005
I think I would actually have more trouble figuring out how to cause Apache to run .php5 files through the proper interpretter than I would doing the compilation.

I know how to add additional file extensions to the current php interpretter, but I don't have to put any sort of path for that, I just associate .xxx files with "php" in an .htaccess file with "AddType". To point them at a different interpretter in my own home directory... I'm lost. :)
Permalink muppet 
March 4th, 2005
Generally PHP is compiled as an Apache module. You simply associate a (set of) file extensions with that module. You can't (unless you're really determined) run two different versions of PHP as Apache modules at the same time.

To run both, you take one of the versions and use plain old CGI or (much better option) FastCGI.

"To point them at a different interpretter in my own home directory... I'm lost. :)"

I don't think you install it into your home directory and use .htaccess. The configuration items you need to set can only be site in the main Apache configuration. Something like this might work:

ScriptAlias /php/ "/path-to-php/"
AddType application/x-httpd-php5 .php5
Action application/x-httpd-php5 "/php/php-cgi"

Unfortunately, the ScriptAlias command is not valid within an .htaccess file.
Permalink Almost Anonymous 
March 4th, 2005
The Apache on my host must be hacked, then, because I can associate extensions with different applications via .htaccess files in my home directory. I'm on shared hosting and so I don't have access to http.conf
Permalink muppet 
March 4th, 2005
Well AddType will work in an .htaccess but ScriptAlias won't and you need both, I believe, to do it.
Permalink Almost Anonymous 
March 4th, 2005
hmm.. I think my host has some provision for that, but it's only an issue if I attempt it anyway. :)
Permalink muppet 
March 5th, 2005

This topic was orginally posted to the off-topic forum of the
Joel on Software discussion board.

Other topics: March, 2005 Other topics: March, 2005 Recent topics Recent topics