PHP 8.4.6 Released!

Apache Functions

Table of Contents

add a note

User Contributed Notes 5 notes

up
3
outofnet at mail dot ru
20 years ago
Important info for Apache2 users that have several virtual hosts.

It seems php_flag directive has a different behaviour under Apache 2 (from what it is under 1.3) when used inside <VirtualHost> block.

If you override global php.ini settings with php_flag for one of your virtual host - then your other non-customized virtual hosts may use this overrided settings as well. php_flag records are messed up among different virtual hosts under single Apache 2 server. It may result from Apache 2 multi-thread nature.

Here is an example:

Suppose you have two Virtual hosts: V1 and V2.
For V1 in Apache configuration you use
php_flag magic_quotes_gpc 1
V2 is supposed to use global php.ini settings, so you didn't put any php_flag records into Apache conf for V2 (this worked under Apache 1.3).
And your default php.ini settings are:
php_flag magic_quotes_gpc 0

When you run your server you'll notice that magic quotes is (sometimes) set to On at V2!
The value turns On at V2 when there have been a previous request to V1.

To solve the problem either move php_flag into .htaccess located inside customized virtual host directory OR put php_flag with default settings into all your <VirtualHost> blocks that are not customized. So for V2 put:
php_flag magic_quotes_gpc 0

It is critical to be very carefull with php_flag engine 0.

My configuration is:
PHP 4.3.4, Apache 2.0.50, Linux RedHat 9
up
2
henk_nicolai at REMOVE-THIS at hotmail dot com
22 years ago
My Apache server has a problem when someone enters a URI like: "http://www.php.net/manual/"), and my idea was to do the same when the user adds a slash too much:

<?php
$req
= $_SERVER['REQUEST_URI'];
/ Remove rubbish.
$newReq = ereg_replace ('index.php[^?]*', 'index.php', $req);
if (
strlen($newReq) < strlen($req)) {
header ('Location: '.$newReq);
header ('HTTP/1.0 301 Moved Permanently');
die;
/ Don't send any more output.
}
unset(
$req); unset($newReq);

... (
rest of the script) ...
?>

Replace every occurence of 'index.php' with your filename and you're done. Hope it helps. :-)

(Note: I'm not using fragments in my URI's (like 'index.php#bottom'), and this code may not do what you want if you are using them.)
up
-1
cjm2 at earthling dot net
23 years ago
If you are trying to find a Handler to use with apache's mod_mime functions (e.g. SetHandler). Use the MIME type associated with php.

e.g. SetHandler application/x-httpd-php
up
-2
bgshea at gmail dot com
19 years ago
here is a dynamic version of henk_nicolai at REMOVE-THIS at hotmail dot com's code

$req = $_SERVER['REQUEST_URI'];
/ Remove rubbish.
$newReq = ereg_replace ( $_SERVER['SCRIPT_NAME'] . '[^?]*', $_SERVER['SCRIPT_NAME'], $req);
if (strlen($newReq) < strlen($req))
{
header ('Location: '.$newReq);
header ('HTTP/1.0 301 Moved Permanently');
die; / Don't send any more output.
}
unset($req);
unset($newReq);

this can be placed at the top of any file that is to be access by the URI.
up
-5
pike
19 years ago
to henk_nicolai

the behaviour you describe is not a "glitch" of apache :-). an url like
"http://nl2.php.net/reserved.variables . PATH_INFO is not related to the php pathinfo() function

$2c,
*pike
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant