note 120978 added to reserved.variables.server

From: Date: Wed, 12 Apr 2017 23:44:16 +0000
Subject: note 120978 added to reserved.variables.server
Groups: php.notes 
Request: Send a blank email to php-notes+get-209024@lists.php.net to get a copy of this message
Guide to absolute paths... Data: __FILE__ Data type: String Purpose: The absolute pathname of the running PHP file, including the filename. Caveat: This is not the file called by the PHP processor, it's what is running. So if you are inside an include, it's the include. Caveat: Symbolic links are pre-resolved, so don't trust comparison of paths to be accurate. Caveat: Don't assume all operating systems use '/' for the directory separator. Works on web mode: Yes Works on CLI mode: Yes Data: __DIR__ Data type: String Purpose: The absolute pathname to the running PHP file, excluding the filename Caveat: This is not the file called by the PHP processor, it's what is running. So if you are inside an include, it's the include. Caveat: Symbolic links are pre-resolved, so don't trust comparison of paths to be accurate. Caveat: Don't assume all operating systems use '/' for the directory separator. Works on web mode: Yes Works on CLI mode: Yes Data: $_SERVER['SCRIPT_FILENAME'] Data type: String Purpose: The absolute pathname of the origin PHP file, including the filename Caveat: Not set on all PHP environments, may need setting by copying from __FILE__ before other files are included. Caveat: Symbolic links are not pre-resolved, use PHP's 'realpath' function if you need it resolved. Caveat: Don't assume all operating systems use '/' for the directory separator. Caveat: "Filename" makes you think it is just a filename, but it really is the full absolute pathname. Read the identifier as "Script's filesystem (path)name". Works on web mode: Yes Works on CLI mode: Yes Data: $_SERVER['PATH_TRANSLATED'] Data type: String Purpose: The absolute pathname of the origin PHP file, including the filename Caveat: It's probably not set, best to just not use it. Just use realpath($_SERVER['SCRIPT_FILENAME']) (and be aware that itself may need to have been emulated). Caveat: Symbolic links are pre-resolved, so don't trust comparison of paths to be accurate. Caveat: Don't assume all operating systems use '/' for the directory separator. Works on web mode: Yes Works on CLI mode: No Data: $_SERVER['DOCUMENT_ROOT'] Data type: String Purpose: Get the absolute path to the web server's document root. No trailing slash. Caveat: Don't trust this to be set, or set correctly, unless you control the server environment. Caveat: May or may not have symbolic links pre-resolved, use PHP's 'realpath' function if you need it resolved. Caveat: Don't assume all operating systems use '/' for the directory separator. Works on web mode: Yes Works on CLI mode: No Note that if something is not set it may be missing from $_SERVER, or it may be blank, so use PHP's 'empty' function for your test. Note that if you call "php --info" on the command line then naturally some of these settings are going to be blank, as no PHP file is involved. ---- Server IP: 72.52.91.14 Probable Submitter: 86.3.44.227 ---- Manual Page -- http://php.net/manual/en/reserved.variables.server.php Edit -- https://master.php.net/note/edit/120978 Del: integrated -- https://master.php.net/note/delete/120978/integrated Del: useless -- https://master.php.net/note/delete/120978/useless Del: bad code -- https://master.php.net/note/delete/120978/bad+code Del: spam -- https://master.php.net/note/delete/120978/spam Del: non-english -- https://master.php.net/note/delete/120978/non-english Del: in docs -- https://master.php.net/note/delete/120978/in+docs Del: other reasons-- https://master.php.net/note/delete/120978 Reject -- https://master.php.net/note/reject/120978 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#209024) next »