note 63388 added to function.dirname

From: Date: Tue, 21 Mar 2006 22:40:29 +0000
Subject: note 63388 added to function.dirname
Groups: php.notes 
Request: Send a blank email to php-notes+get-106182@lists.php.net to get a copy of this message
OK, I'll bite :-) Things that could be improved are: 1. PHP_SELF isn't always reliable. (Particularly various (mis-)configured FastCgi installations.) REQUEST_URI is, and it's reasonably easy to parse. Even better, REQUEST_URI also contains the server name. 2. When concatenating, you don't need that initial empty string. 3. dirname() has a borderline case (at least in 4.4.4): if the URL ends with a slash, the path part preceding it is stripped, too. I.e. if the script is called as http://example.com/path/to/script/index.php, dirname() will do the Right Thing, but http://example.com/path/to/script/ will come out as http://example.com/path/to. (*Very* bewildering if the customer phones you about that...) Luckily, that's easy to fix by adding a letter (actually anything but a slash) to the URL. Giving: <?php list ($url, $query_string) = explode ('?', $_SERVER ['REQUEST_URI'], 2); $urldir = dirname ($url . 'x'); ?> ---- Server IP: 66.163.161.117 Probable Submitter: 84.175.1.48 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.dirname.php Edit -- http://master.php.net/note/edit/63388 Del: integrated -- http://master.php.net/note/delete/63388/integrated Del: useless -- http://master.php.net/note/delete/63388/useless Del: bad code -- http://master.php.net/note/delete/63388/bad+code Del: spam -- http://master.php.net/note/delete/63388/spam Del: non-english -- http://master.php.net/note/delete/63388/non-english Del: in docs -- http://master.php.net/note/delete/63388/in+docs Del: other reasons-- http://master.php.net/note/delete/63388 Reject -- http://master.php.net/note/reject/63388 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#106182) next »