php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21154 $_SERVER[PHP_SELF] empty in cgi
Submitted: 2002-12-22 21:31 UTC Modified: 2002-12-24 15:07 UTC
From: george at omniti dot com Assigned:
Status: Not a bug Package: Other web server
PHP Version: 4.3.0RC4 OS: mac osx
Private report: No CVE-ID: None
 [2002-12-22 21:31 UTC] george at omniti dot com
<?php
print_r($_SERVER);
?>

returns:

22:28:26(george@ool-18bced28)[~/Advanced PHP/examples]> php 
a.php               
Content-type: text/html                                                         
X-Powered-By: PHP/4.3.0-dev                                                     
                                                                                
Array                                                                           
(                                                                               
    [HOME] => /Users/george                                                     
    [SHELL] => /bin/tcsh                                                        
    [USER] => george                                                            
    [LANG] => en                                                                
    [PATH] => /sw/bin:/sw/sbin:/bin:/usr/bin:/Users/george/
bin:/usr/sbin:/opt/GN
Upgcc/bin:/opt/GNUxemacs/bin:/usr/local/bin:/usr/local/
sbin:/usr/openwin/bin:/us
r/dt/bin:/usr/ccs/bin:/usr/proc/bin:/usr/ucb:/usr/X11R6/
bin:/sw/bin:/sw/sbin:.:/
usr/X11R6/bin                                                                   
    [__CF_USER_TEXT_ENCODING] => 0x1F5:0:0                                      
    [TERM] => vt100                                                             
    [PWD] => /Users/george/Advanced PHP/examples                                
    [HOSTTYPE] => macintosh                                                     
    [VENDOR] => apple                                                           
    [OSTYPE] => darwin                                                          
    [MACHTYPE] => powerpc                                                       
    [SHLVL] => 1                                                                
    [LOGNAME] => george                                                         
    [GROUP] => staff                                                            
    [HOST] => ool-18bced28.dyn.optonline.net                                    
    [HOSTTAG] => maya [Omniti/mobile]                                           
    [MANPATH] => /usr/share/man:/usr/openwin/share/man:/
usr/man:/usr/local/man:/
opt/SUNWwabi/man:/usr/local/lib/perl5/man:/opt/GNUpgcc/
man:/opt/GNUxemacs/man   
    [INFOPATH] => /sw/share/info:/sw/info:/usr/local/share/
info:/usr/local/lib/i
nfo:/usr/local/info:/usr/share/info                                             
    [PERL5LIB] => /sw/lib/perl5                                                 
    [EDITOR] => vi                                                              
    [VISUAL] => vi                                                              
    [DISPLAY] => :0.0                                                           
    [CVS_RSH] => ssh                                                            
    [OPENWINHOME] => /usr/openwin                                               
    [XFILESEARCHPATH] => /usr/dt/lib/%T/%N%S                                    
    [XGLHOME] => /opt/SUNWits/Graphics-sw/xgl                                   
    [LD_LIBRARY_PATH] => /usr/lib:/usr/dt/lib:/usr/openwin/
lib:/usr/ucblib:/usr/
local/lib:.                                                                     
    [XILHOME] => /opt/SUNWits/Graphics-sw/xil                                   
    [MOTIFHOME] => /usr/dt                                                      
    [UIDPATH] => /opt/SUNWmfdm                                                  
    [XMBINDDIR] => /usr/dt/lib/bindings                                         
    [GUIDEHOME] => /opt/SUNWguide                                               
    [PHP_SELF] =>                                                               
    [argv] => Array                                                             
        (                                                                       
            [0] => a.php                                                        
        )                                                                       
                                                                                
    [argc] => 1                                                                 
)         

note PHP_SELF is unset.  Running the same under cli yields 
correct result:

22:31:00(george@ool-18bced28)[~/Advanced PHP/examples]> ~/
src/php4-STABLE-200212
210230/sapi/cli/php ~/Advanced\ PHP/examples/a.php                              
Array                                                                           
(                                                                               
    [HOME] => /Users/george                                                     
    [SHELL] => /bin/tcsh                                                        
    [USER] => george                                                            
    [LANG] => en                                                                
    [PATH] => /sw/bin:/sw/sbin:/bin:/usr/bin:/Users/george/
bin:/usr/sbin:/opt/GN
Upgcc/bin:/opt/GNUxemacs/bin:/usr/local/bin:/usr/local/
sbin:/usr/openwin/bin:/us
r/dt/bin:/usr/ccs/bin:/usr/proc/bin:/usr/ucb:/usr/X11R6/
bin:/sw/bin:/sw/sbin:.:/
usr/X11R6/bin                                                                   
    [__CF_USER_TEXT_ENCODING] => 0x1F5:0:0                                      
    [TERM] => vt100                                                             
    [PWD] => /Users/george/Advanced PHP/examples                                
    [HOSTTYPE] => macintosh                                                     
    [VENDOR] => apple                                                           
    [OSTYPE] => darwin                                                          
    [MACHTYPE] => powerpc                                                       
    [SHLVL] => 1                                                                
    [LOGNAME] => george                                                         
    [GROUP] => staff                                                            
    [HOST] => ool-18bced28.dyn.optonline.net                                    
    [HOSTTAG] => maya [Omniti/mobile]                                           
    [MANPATH] => /usr/share/man:/usr/openwin/share/man:/
usr/man:/usr/local/man:/
opt/SUNWwabi/man:/usr/local/lib/perl5/man:/opt/GNUpgcc/
man:/opt/GNUxemacs/man   
    [INFOPATH] => /sw/share/info:/sw/info:/usr/local/share/
info:/usr/local/lib/i
nfo:/usr/local/info:/usr/share/info                                             
    [PERL5LIB] => /sw/lib/perl5                                                 
    [EDITOR] => vi                                                              
    [VISUAL] => vi                                                              
    [DISPLAY] => :0.0                                                           
    [CVS_RSH] => ssh                                                            
    [OPENWINHOME] => /usr/openwin                                               
    [XFILESEARCHPATH] => /usr/dt/lib/%T/%N%S                                    
    [XGLHOME] => /opt/SUNWits/Graphics-sw/xgl                                   
    [LD_LIBRARY_PATH] => /usr/lib:/usr/dt/lib:/usr/openwin/
lib:/usr/ucblib:/usr/
local/lib:.                                                                     
    [XILHOME] => /opt/SUNWits/Graphics-sw/xil                                   
    [MOTIFHOME] => /usr/dt                                                      
    [UIDPATH] => /opt/SUNWmfdm                                                  
    [XMBINDDIR] => /usr/dt/lib/bindings                                         
    [GUIDEHOME] => /opt/SUNWguide                                               
    [PHP_SELF] => /Users/george/Advanced PHP/examples/a.php                     
    [SCRIPT_NAME] => /Users/george/Advanced PHP/examples/
a.php                  
    [SCRIPT_FILENAME] => /Users/george/Advanced PHP/
examples/a.php              
    [PATH_TRANSLATED] => /Users/george/Advanced PHP/
examples/a.php              
    [DOCUMENT_ROOT] =>                                                          
    [argv] => Array                                                             
        (                                                                       
            [0] => /Users/george/Advanced PHP/examples/
a.php                    
        )                                                                       
                                                                                
    [argc] => 1                                                                 
)   


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-22 21:36 UTC] george at omniti dot com
I should note that the cgi and cli are both being run by 
hand from a shell (not exec'd from a webserver).
 [2002-12-23 05:25 UTC] wez@php.net
CGI needs specific environmental variables to be set in order to determine PHP_SELF.
Running from the command line does not (usually) have the environment set up as described in the CGI spec, and that is the reason it's missing.

If you think about it, it makes sense; how can it determine the relative path to the root of the web server when it is not actually running under a web server?

http://www.php.net/manual/en/reserved.variables.php#reserved.variables.globals
States:

"
'PHP_SELF'
The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. 

If PHP is running as a command-line processor, this variable is not available.
"

So I'm marking this report as bogus (nothing personal!).
 [2002-12-23 10:19 UTC] philip@php.net
Why does CLI have all of these?  
Why is PHP_SELF empty as opposed to not existing at all?
 [2002-12-23 10:25 UTC] george at omniti dot com
Doesn't make sense to me.  Even if not PHP_SELF, then at 
least SCRIPT_FILE or SCRIPT_FILENAME (both also blank) 
should be defined.  These are certainly well-defined in any 
context.
 [2002-12-24 15:07 UTC] kalowsky@php.net
Marking as bogus as well.

I had originally thought the same way George, but after making  many inquries about this on the php-dev lists (see archives for more details) I was informed why this didn't work like so pretty well.  Wez's sub-explination does share a lot of the same info too.  I was also lead to believe that this was one of the main reasons that CLI and CGI were split apart... although given recent PHP-Dev convos, I have that belief thrown into a state of confusion.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC