note 48860 added to reserved.variables

From: Date: Sun, 09 Jan 2005 21:27:04 +0000
Subject: note 48860 added to reserved.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-83005@lists.php.net to get a copy of this message
Running Xitami in Windows 2000 and PHP 4.3.7, nor PHP_SELF or SCRIPT_FILENAME is not availiable. Trying SCRIPT_NAME instead. Here is a function that returns the filename of a script without slashes. Good for use in HTML FORM ACTION=""-arguments... function getThisFile() { /* try to use PHP_SELF first... */ if (!empty($_SERVER['PHP_SELF'])) { $strScript = $_SERVER['PHP_SELF']; /* otherwise, try SCRIPT_NAME */ } else if (!empty($_SERVER['SCRIPT_NAME'])) { $strScript = @$_SERVER['SCRIPT_NAME']; /* last resort - quit out and return nothing */ } else { return null; } /* fint last frontslash in filename */ $intLastSlash = strrpos($strScript, "/"); /* check if last backslash is more far away in filename */ if (strrpos($strScript, "\\")>$intLastSlash) { /* if so, use the backslash position instead */ $intLastSlash = strrpos($strScript, "\\"); } /* cut out from the last slash and to the end of the filename */ return substr($strScript, $intLastSlash+1, strlen($strScript)); } Tested on PHP 4.3.7/Win32 and PHP 5.0.3/Linux. You may add more filepaths to the first if-section to get more chances to catch up the filename if you can. ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48860 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48860&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48860&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48860&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48860&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48860&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48860&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48860&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83005) next »