Hi,

I have found PHP_SELF variable very confusing.
Maybe you can prove me wrong.

I thought that this variable can be used as a self reference
URL address for the currently running script, e.g.:

  <form action="<?php echo $PHP_SELF ?>" ...

But it seems that PHP_SELF variable have different contents in apache/module API
and in cgi api (PHP version 4.2.2).

In sapi/apache/mod_php4.c PHP_SELF is always equal to decoded
request uri:

  php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, 
track_vars_array TSRMLS_CC);

in sapi/cgi/cgi_main.c PHP_SELF is equal to PHP_INFO
env. variable if it exists, otherwise it is copied from SCRIPT_NAME:

        php_register_variable("PHP_SELF", (SG(request_info).request_uri
           ? SG(request_info).request_uri:""), track_vars_array TSRMLS_CC);

  and later:

        SG(request_info).request_uri = getenv("PATH_INFO");
        if (!SG(request_info).request_uri) {
                SG(request_info).request_uri = getenv("SCRIPT_NAME");
        }

I.e. if I call: http://server/dir/file.php/path-info?q=1
I would get:

           Apache module              PHP CGI
PHP_SELF   /dir/file.php/path-info    /path-info

and if I call http://server/dir/file.php?q=1, the result is:

           Apache module              PHP CGI
PHP_SELF   /dir/file.php/path-info    /dir/file.php


IMHO:
I think cgi_main.c should be patched in such a way, that PHP_SELF
should always be equal to concatenation of SCRIPT_NAME and PATH_INFO.

But there is a catch - php_fopen_primary_script() function
assumes that SG(request_info).request_uri contains PATH_INFO
variable and glues together doc_root (if set) and that path_info
string to build php file path. Maybe someone else, who understands
dependencies deeper could generate apropriate patch for PHP_SELF variable.

Best regards,

-- 
Piotr Klaban

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to