|
|
|
Someone asked this on the PHP list today, so here it is for everyone!
$_SERVER['PHP_SELF'] (or even just $PHP_SELF on most PHP installs) is great for getting the name of
the script/url currently being executed, or for pointing a script to itself, etc etc.
But sometimes you also need the querystring (everything after the '?') as well.
The one line version:
| <?php
$foo = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
?> | |
... this works fine, but if there's no query string, it will still have the '?', so the better
version:
| <?php
if($_SERVER['QUERY_STRING']) {
$foo = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
} else {
$foo = $_SERVER['PHP_SELF'];
}
?> | |
In the case of a URL like http://www.preshrunk.com/history.php?page=browse&year=2002, $foo would
contain 'page=browse&year=2002'.
The above assumes PHP >= 4.1 (superglobal arrays used). |
|
| Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI Categories : Variables, PHP Options and Info, Arrays, URLs, PHP | | | How to make sure a that $foo is from a cookie and not from the URI. Categories : PHP, Variables, Global Variables, Cookies | | | Initialize global variables for every field in a table.
This version requires that phplib is installed on your
server. Categories : Global Variables, MySQL, PHP, Variables | | | pick up an array of variables from a query string such as:
http://www.archipro.com/test.php?state=AB&state=BC
Categories : PHP, Strings, URLs, Global Variables | | | Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with
PHP 4.2.0 Categories : PHP, HTML and PHP, Global Variables, Cookies, Variables | | | Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables | | | Global Dump Highlighted Categories : PHP, Variables, Global Variables | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | php jump urls...the best way Categories : PHP, URLs, Filesystem | | | PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside. Categories : PHP, Arrays, Variables | | | translate.php - Assocciative array example, passing a reference to a function. Categories : PHP, Arrays, Languages, Variables | | | This functions compares the current PHP version with a
desired version. Because of the 3 tiered version system, a
direct compare of a string to phpversion() will not be
accurate. Categories : PHP Configuration, PHP, Variables | | | A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors Categories : PHP, Variables, Errors and Logging | | | How to control the number of decimal places when outputting numbers. Categories : PHP, Strings, Variables | |
| | | | Sarah King wrote :979
Consider the case of an included script
If it needs to know it`s own location (and you don`t want to hardcode it) how does that script know it`s location?
| |
|
|
|