Page 1 of 2
Page not reading variables in URL
Posted: Tue Oct 07, 2003 12:21 pm
by tsg
I have someone setting up PHP on a server, but the pages do not seem to pick up the variable in the URL ... for example:
domain.com/page.php?variable=$test
Say I am pulling the $test information from the database, but the page doesn't read it.
Any ideas on what I can tell him to change to make it work in the set up? I am kinda at a loss on this.
Thanks,
Tim
Posted: Tue Oct 07, 2003 12:27 pm
by qads
if that does't work then try:
Code: Select all
<?php
echo $HTTP_GET_VARS['variable'];
?>
Posted: Tue Oct 07, 2003 12:30 pm
by tsg
Have it working now. It was the register_globals, they were off and I didn't know (I should have checked that first).
I had him turn it on ... if he hadn't, I would have had to recode to what you had posted. I guess I should start making that a habit anyways.
Thanks,
Tim
Posted: Tue Oct 07, 2003 2:04 pm
by mudkicker
some advice: you should make a habit to use it off and write your codes like qads told.
have a nice day!

Posted: Tue Oct 07, 2003 2:06 pm
by Cruzado_Mainfrm
dude, u have to start making a habit of using the $_GET[] variables, do u want someone to break in your site

? then follow the rules dude
that register_globals should be turned off, and by the way, the people at PHP are going to deprecate it
Posted: Tue Oct 07, 2003 2:15 pm
by tsg
thanks for the input guys ... always something to learn ya know.
And for "following the rules" .. the rules in my PHP handbook I bought a couple of years ago does not talk about that way of doing it. However, I constantly find myself implimenting a better, more secure way of doing things. It's an ongoing process as we progress.
Tim (dude)
Posted: Tue Oct 07, 2003 4:06 pm
by Sinnix
Yeah, no PHP book I own says anything about $_POST or $_GET (not even the one I bought two weeks ago), but the reality is that this has been in place for a while now and if you want your apps to keep working, you'ld best get in the habit now!

Posted: Tue Oct 07, 2003 4:06 pm
by qads
old books (1 year or older) are about php 4.0 or php 4.01 at best, in those version register_globals are set to on, i myself was in shock when they turned them off in 4.2 lol..all my code screwed up and i was alittle mad lol..but little extra time saves headachs later

Posted: Tue Oct 07, 2003 5:23 pm
by mudkicker
Posted: Tue Oct 07, 2003 5:31 pm
by qads
lol..uh..thanks

Posted: Tue Oct 07, 2003 7:22 pm
by tsg
Just to follow up on a couple of things ...
When I use the $_GET['thing'] .. is that only for variables coming from the url? Would I use that for variables pulled from the database? (I don't think so, but want to be reassured)
When I use it doing a query on the database, there "WHERE this_item='$_GET['thing']'" throws an error, but this works: "WHERE this_item='$_GET[thing]'" (notice no ' ' inside the []) .. Is that cool?
I do use $_POST[] on forms ... I guess I should have picked this up at the same time ...
that's all for now ...
thanks,
Tim
Posted: Tue Oct 07, 2003 7:30 pm
by Paddy
Not sure why your second attempt worked. Some guru might be able to answer that, but I think this is what you want.
Code: Select all
<?php
$thing = $_GET['thing'];
$result = mysql_query("select * from atable where this_item='".$thing."'") or exit();
?>
And yes, to get data from a form you use POST.
Posted: Tue Oct 07, 2003 8:09 pm
by qads
use this
ONLY if $thing is a number
Code: Select all
<?php
$thing = (int)$_GET['thing'];
$result = mysql_query("select * from atable where this_item='$thing'") or exit();
?>
Posted: Tue Oct 07, 2003 8:12 pm
by Cruzado_Mainfrm
u can access variables in $_POST[] when using forms that have POST as method, ex: method="POST", if you set it to GET then variables are going to be passed in the url(not recommended) and can be accessed obviously with $_GET[]
Posted: Tue Oct 07, 2003 8:12 pm
by tsg
In this example:
WHERE this_item='$_GET[thing]'
$thing is a number in the url (?thing=9) and is working ... is that "correct"?