note 56633 added to reserved.variables

From: Date: Sat, 10 Sep 2005 06:32:29 +0000
Subject: note 56633 added to reserved.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-94982@lists.php.net to get a copy of this message
This code will help get just the name of the script your using: THE PROBLEM -------------------------------------------------------- Using $PHP_SELF or $_SERVER[PHP_SELF] FOR THE URL > http://yourdomain.com/location/of/myphpscript.php will output location/of/myphpscript.php FOR THE URL > http://yourdomain.com/location/of/myphpscript.php?lang=es&id=2 will output location/of/myphpscript.php?lang=es&id=2 But you only want to output myphpscript.php this cannot be done using $_SERVER[PHP_SELF] THE SOLUTION -------------------------------------------------------- Detect if its a WINDOWS path and convert it into a UNIX path If its a UNIX path it won do nothing, the result will be myphpscript.php I think also will help correcting problems with WINDOWS path's as you will notice in order to make a replace of a single \ you have to use 4 \\\\ $scriptrealpath = ereg_replace("\\\\",'/', realpath(".")); $scriptlocpath = ereg_replace("\\\\\\\\",'/', $_SERVER[PATH_TRANSLATED]); $LOAD_SCRIPT = ereg_replace("$scriptrealpath/", "", "$scriptlocpath"); -------------------------------------------------------- IN WINDOWS the output will be realpath(".") - C:\html\location\of $_SERVER[PATH_TRANSLATED] - C:\\html\\location\\of\\myphpscript.php $scriptrealpath - C:/htmllocation/of $scriptlocpath - C:/html/location/of/myphpscript.php $LOAD_SCRIPT - myphpscript.php -------------------------------------------------------- In UNIX the output will be realpath(".") - /var/www/location/of $_SERVER[PATH_TRANSLATED] - /var/www/location/of $scriptrealpath - /var/www/location/of $scriptlocpath - /var/www/location/of/myphpscript.php $LOAD_SCRIPT - myphpscript.php ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56633 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56633&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56633&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56633&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56633&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56633&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56633&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56633&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94982) next »