php ?
- Started
- Last post
- 5 Responses
- versa
i am trying to implement some simple php based on a query string var
all i want to do(at this point) is echo a "year" var that is being passed in the query string as, yr=2000, etc.
all i am using is this, and it isn't displaying:
(the link from page one)
[option value="index.php?p=galleryTemp&y...
( and the php on galleryTemp.php page )
[?php
if($HTTP_GET_VARS['yr'])
{
$yr = $_GET['yr'];
}?]
.. further down page ...
[h3 id="title">Gallery / [?php echo "[yr]"; ?][/h3]
thx for any help !
- Anarchitect0
on top of your script try putting
foreach ($_REQUEST as $key => $value) {
$$key = $value;
}since php4.0 register_globals are turned off for security reasons.
- mikotondria20
yeah, that key as value thing is a life saver..
- enobrev0
look for 'superglobals' in the manual. Basically when you pass variables to a script via a get or post, they are put into 3 arrays.
'gets' are put into the $_GET array (stuff passed via url)
'posts' are put into the $_POST array (stuff passed fro m a form with method 'post')
and all of hte above are put into the $_REQUEST array
it's generally best to use $_GET or $_POST as it helps the 'reader' of the script to know exactly where the vars are supposed to come from.
That loop that was given earlier loops through the $_REQUEST array (which has both) and creates local variables for everything passed into the script, so you don't have to use the superglobals throughout the script.
Although, as I've said in the past, even though it adds a few bytes to your scripts, the script is far easier to read and debug if you use the $_GET and $_POST arrays throughout instead of generate locals.
At the end of the day, it's your call..
good luck!
- versa0
thx enobrev...very good explanation for a n00b like me