Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP variables

PHP variables
Thread Tools
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Jun 16, 2003, 01:51 PM
 
How can php put it's query string int a variable?

for example I am calling this script with

whatever.php?main

how do i put "main" into some variable?

--will
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jun 16, 2003, 01:55 PM
 
whatever.php?variable=value

which you access in the script with
$_REQUEST["variable"]

or
$_GET["variable"] for only those passed in the URL (rather than submitted via a form POST)
     
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Jun 16, 2003, 02:00 PM
 
yes, but is there a way to do it without the

variable= part

just

whatever.php?value
     
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status: Offline
Reply With Quote
Jun 16, 2003, 02:03 PM
 
Someone check me on this...

I think depending on your server's configuration, PHP will automatically generate variables to hold the values passed through the URL. In the configuration file, a value called register globals can be set to on or off to determine how PHP handles passed variables. For instance, if you had your whatever.php?main=index.html, PHP could generate a variable $main that has been set to 'index.html' (assuming 'register globals' is set to 'on').

I find it better to follow Mithras' example though, since you never know how a server is going to be configured. As far as I know, PHP's Superglobal variables can always be accessed. "It's better to assume that only the superglobal variables will be available and code accordingly."

Check here for more info.

HTH
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
     
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Jun 16, 2003, 02:15 PM
 
i think i figured out what i was trying to do:

foreach($HTTP_GET_VARS as $key=>$value){
$query .=$key;
}

which will cause query to equal main when you call whatever.php?main

and query will equal mainothermain when you call whatever.php?main&othermain

--will
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:43 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2