note 79811 added to reserved.variables

From: Date: Thu, 13 Dec 2007 16:40:11 +0000
Subject: note 79811 added to reserved.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-133426@lists.php.net to get a copy of this message
In addition to mfyahya at gmail dot com (2007-06-07 03:33): If You are working with the Apache module mod_rewrite and want to set some environment vars, the Apache manual says this vars could be accessed in CGI using $ENV{VAR}. In PHP You might want to write $_ENV['VAR'] to get the value of VAR, but You have to access if via $_SERVER, and in some different ways: 1. Example: .htaccess and example.php RewriteEngine on RewriteRule ^?var1=([^;]*);var2=([^;]*)$ \ - [E=VAR1:$1,E=VAR2:$2] <?php echo($_SERVER['VAR1']."\r\n" .$_SERVER['VAR2']); ?> 2. Example: .htaccess and index.php RewriteEngine on RewriteRule ^index\.php$ - [L] RewriteRule ?var1=([^;]*);var2=([^;]*)$ \ index.php [E=VAR1:$1,E=VAR2:$2] <?php echo($_SERVER['REDIRECT_VAR1']."\r\n" .$_SERVER['REDIRECT_VAR2']); ?> Note: If any RewriteRule matches, an internal redirect than restarts (after the last defined rule, or immediately after the matched rule having a L-flag) checking the entire rule set again. For an internal redirect every defined VAR gets an 'REDIRECT_' prefix, i.e. VAR1 will be REDIRECT_VAR1, VAR2 will be REDIRECT_VAR2. Of course, You can (additionally) redefine the original VAR: RewriteEngine on RewriteRule ^index\.php$ \ - [E=VAR1:%{REDIRECT_VAR1},E=VAR2:%{REDIRECT_VAR2},L] RewriteRule ?var1=([^;]*);var2=([^;]*)$ \ index.php [E=VAR1:$1,E=VAR2:$2] With this, You will have $_SERVER['REDIRECT_VAR*'] -and- $_SERVER['VAR*']. *** The given examples are only for explanation, in any case they are not intended to fit Your needs. The "\<CRLF><SP>" in the .htaccess examples are only for display purpose, they should not occur in a real .htaccess file. The argument separator ';' in links can also be '&', but this may cause some trouble with HTML/XHTML. See the following pages for more information about this issue: - http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2 - http://www.w3.org/QA/2005/04/php-session ---- Server IP: 217.13.201.10 Probable Submitter: 84.154.105.28 ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.php Edit -- https://master.php.net/note/edit/79811 Del: integrated -- https://master.php.net/note/delete/79811/integrated Del: useless -- https://master.php.net/note/delete/79811/useless Del: bad code -- https://master.php.net/note/delete/79811/bad+code Del: spam -- https://master.php.net/note/delete/79811/spam Del: non-english -- https://master.php.net/note/delete/79811/non-english Del: in docs -- https://master.php.net/note/delete/79811/in+docs Del: other reasons-- https://master.php.net/note/delete/79811 Reject -- https://master.php.net/note/reject/79811 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133426) next »