[thelist] help me understand global variable in PHP
shawn allen
shawn at alterior.net
Thu Jan 2 12:44:00 CST 2003
quoth Tom Dell'Aringa:
> Now, my problem is - I want to pass along $prodname to the next page
> I am going to via the query string. So I have something like
> /path.php?p=$prodname. This variable however is always empty. This
> line of code is OUTSIDE the functions of course.
Without knowing how your host is configured, I'm willing to bet that
PHP's 'register_globals' directive is set to 'off'. This is a Good
Thing(tm). To retrieve a request variable, you have to pull the value
from the $_REQUEST array:
$prodname = $_REQUEST['prodname'];
Or, if you're sure it'll always come from a GET request on the query
string:
$prodname = $_GET['prodname'];
The so-called "superglobals", $_GET, $_POST, $_SERVER, $_REQUEST, and
others, are scope-independent; you won't have to globalize them within
any of your functions. Take a look at the PHP manual page if you need
any more info:
<http://www.php.net/manual/en/language.variables.predefined.php>
--
shawn allen
mailto://shawn@alterior.net
phone://415.577.3961
http://alterior.net
aim://shawnpallen
More information about the thelist
mailing list