p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   Retrieving Query String (http://p2p.wrox.com/showthread.php?t=410)

a5xo3z1 June 11th, 2003 01:45 AM

Retrieving Query String
 
Hi all,

I'm a php newbie, so please bear with me, if this is a sooo easy question.

Consider http://p2p.wrox.com/sql-server-2000-20/9

how can I get the 89 in the Query string FORUM_ID?

Cheers,

Frank

NotNowJohn June 11th, 2003 03:14 AM

$forum_id=$HTTP_GET_VARS['FORUM_ID'] or
$forum_id=$_GET['FORUM_ID']

Regs,
NotNowJohn


...but the Soon is eclipsed by the Moon

a5xo3z1 June 11th, 2003 03:37 AM

Thanks NotNowJohn,

what is the scope (lifecycle?) of
$HTTP_GET_VARS['FORUM_ID']. In other words, how long is $HTTP_GET_VARS['FORUM_ID'] valid?

Cheers,

Frank

NotNowJohn June 11th, 2003 05:04 AM

This value (and whole array, of couse) is available on the whole page.
The value FORUM_ID=89 can be added to the end of the URL either
by user's typing and by the script.
All "URL addings" (everything after "?" in he query string) are available
in the associative array named $HTTP_GET_VARS, so if you typed
http://www.someul.com/page1.php?a=3&b=4&c=5
on the page1.asp you can use the variable's values cause it's automatcally
configured
$HTTP_GET_VARS["a"]=3
$HTTP_GET_VARS["b"]=4
$HTTP_GET_VARS["c"]=5

In other words each user request create this array and initialize his members.

HTH.

...but the Soon is eclipsed by the Moon

a5xo3z1 June 11th, 2003 05:11 AM

Yes, it does!

Thank you!

Cheers,

Frank

cmiller June 11th, 2003 09:50 AM

There's actually an even easier way to get the variable from the query string. if your querystring is ***.php?FORUM_ID=85 Then all you would have to do in your PHP is use $FORUM_ID where you want it to show up in the script. That's obviously the simplest way though. There are MANY more complicated ways like some of the above.

----------
~cmiller

a5xo3z1 June 11th, 2003 09:56 AM

Hello ~cmiller,

Quote:

quote:Originally posted by cmiller
 There's actually an even easier way to get the variable from the query string. if your querystring is ***.php?FORUM_ID=85 Then all you would have to do in your PHP is use $FORUM_ID where you want it to show up in the script. That's obviously the simplest way though. There are MANY more complicated ways like some of the above.
I haven't the opportunity to check this now, but does it also work for multiple parameters like ?FORUM_ID=89&TOPIC_ID=454...

Cheers,

Frank

a5xo3z1 June 12th, 2003 01:09 AM

Hello ~cmiller,

hmm...your solution isn't working. Given the above example

echo $FORUM_ID yields an error message like 'Undefined variable'???

Since I know ASP programming I found a solution that's familiar to me. I use
$_REQUEST['FORUM_ID']. which also seems to work

Cheers,

Frank

NotNowJohn June 12th, 2003 03:18 AM

Frank,

In the php config file there is an option to register global variables
If register_global=on then all variables (all request parts which can be interpreted as a variable) are available in the manner cmiller mentioned.
However, it is recommended, and most of admins accept this recmd, that this option will be disabled (register_global=off), and that the script has to access these values through several associative arrays.

Regs,
NotNowJohn

...but the Soon is eclipsed by the Moon

a5xo3z1 June 12th, 2003 03:27 AM

Thanks NotNowJohn,

for explanation. If there is no issue with $_REQUEST, I'll use this.

Cheers,

Frank


All times are GMT -4. The time now is 11:26 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.