 |
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

June 11th, 2003, 01:45 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
__________________
-----------------------
--Frank
http://www.insidesql.de
-----------------------
|

June 11th, 2003, 03:14 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
$forum_id=$HTTP_GET_VARS['FORUM_ID'] or
$forum_id=$_GET['FORUM_ID']
Regs,
NotNowJohn
...but the Soon is eclipsed by the Moon
|

June 11th, 2003, 03:37 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 11th, 2003, 05:04 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 11th, 2003, 05:11 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, it does!
Thank you!
Cheers,
Frank
|

June 11th, 2003, 09:50 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 11th, 2003, 09:56 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 12th, 2003, 01:09 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 12th, 2003, 03:18 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 12th, 2003, 03:27 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks NotNowJohn,
for explanation. If there is no issue with $_REQUEST, I'll use this.
Cheers,
Frank
|
|
 |