Possible Duplicate:
global variables in php not working as expected
I have a php function that runs on every page of a website, it use a global variable, for example:
$var = "test";
function test() {
global $var;
echo $var;
}
This works fine when accessing /anyFile.php directly, but the website uses an htaccess file to rewrite urls, something like:
RewriteRule ^action/(.*)$ /index.php?action=$1 [L]
When an url is rewrited by the htaccess, the function doesn’t work, the $var is not set.
What could be this happening and how can I fix it? (I NEED to use “global”, otherwise I’d need to recode a lot of things.
You need to use
[QSA,L]instead of[L]:QSA stands for Query String Append, and forwards the query string (the part after the
?in the url) to the PHP script.By the way, you should not use register_globals (deprecated as of PHP 5.3 and removed as of PHP 5.4), but use the
$_GETsuperglobal instead.— edit —
Following your comment below (you can’t modify the .htaccess), you’re out of luck. Your only solution is to parse the query string in the request URI, and use that as you would use the
$_GETsuperglobal:I strongly advise you to get the
.htaccessmodified for you, though.