473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Variable passed in GET or POST array

I have finally started coding with register_globals off (crowd roars -
yeay!).

This has created a situation that I am not sure how I should handle. I
have scripts (pages) that can receive an input variable from the POST
array (initial entry) or it could be in the GET array (go back and
re-edit a form, for instance.)

In my old sloppy scripting days this was no problem, as I had
register_globals on and would merely access the the input variable by
it's local name (whether it was POST or GET made no difference).

What's the best way to handle this situation where I am not sure if the
input variable is in the GET array or the POST array? My guess is to
test for the presence of the variable (isset, != '') in either array and
then copy it to a local variable from that array.

Is that the best, only, or most efficient way to handle that?

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jan 19 '06 #1
5 5356


Chuck Anderson wrote:
I have finally started coding with register_globals off (crowd roars -
yeay!).

This has created a situation that I am not sure how I should handle. I
have scripts (pages) that can receive an input variable from the POST
array (initial entry) or it could be in the GET array (go back and
re-edit a form, for instance.)

In my old sloppy scripting days this was no problem, as I had
register_globals on and would merely access the the input variable by
it's local name (whether it was POST or GET made no difference).

What's the best way to handle this situation where I am not sure if the
input variable is in the GET array or the POST array? My guess is to
test for the presence of the variable (isset, != '') in either array and
then copy it to a local variable from that array.

Is that the best, only, or most efficient way to handle that?

--
*****************************
Chuck Anderson · Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

variables will be in the format:

$_POST['variablename'] or $_GET['variablename']

When troubleshooting with PHP it is very easy to insert a phpinfo();
command in your script and you can see ALL of the possible variables
and formats of those variables.

Michael Austin
Consultant

Jan 19 '06 #2
"Chuck Anderson" <we************@seemy.sig> kirjoitti
viestissä:U7********************@comcast.com...
I have finally started coding with register_globals off (crowd roars -
yeay!).

This has created a situation that I am not sure how I should handle. I
have scripts (pages) that can receive an input variable from the POST
array (initial entry) or it could be in the GET array (go back and re-edit
a form, for instance.)

In my old sloppy scripting days this was no problem, as I had
register_globals on and would merely access the the input variable by it's
local name (whether it was POST or GET made no difference).

What's the best way to handle this situation where I am not sure if the
input variable is in the GET array or the POST array? My guess is to test
for the presence of the variable (isset, != '') in either array and then
copy it to a local variable from that array.

Is that the best, only, or most efficient way to handle that?


$_REQUEST <-- it contains both $_GET and $_POST variables :)

--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <an*******************@gmail.com.NOSPAM.invalid>
Jan 19 '06 #3
Chuck Anderson wrote:
I have finally started coding with register_globals off (crowd roars -
yeay!).
YEAY!
This has created a situation that I am not sure how I should handle. I
have scripts (pages) that can receive an input variable from the POST
array (initial entry) or it could be in the GET array (go back and
re-edit a form, for instance.)
Why is it not POST again?
In my old sloppy scripting days this was no problem, as I had
register_globals on and would merely access the the input variable by
it's local name (whether it was POST or GET made no difference).

What's the best way to handle this situation where I am not sure if the
input variable is in the GET array or the POST array? My guess is to
test for the presence of the variable (isset, != '') in either array and
then copy it to a local variable from that array.
Just know what you want and use it;
if you want something in the POSTed data, use $_POST
if you want something passed in the URL, use $_GET
Is that the best, only, or most efficient way to handle that?


As Kimmo said you can use the $_REQUEST array which is contains
(almost (*)) all the $_GETs and $_POSTs.

(*) The $_REQUEST array will *not* have duplicate keys from $_GET,
$_POST, and $_COOKIE. There's a configuration value that specifies what
order is followed when PHP builds the $_REQUEST array (default is GPC,
meaning GET, POST, COOKIE).

If you have
$_GET['id'] = 4;
$_POST['id'] = 14;
$_COOKIE['id'] = 77;

$_REQUEST['id'] will be 77.

I never needed to use $_REQUEST and I always know whether the user input
comes from $_GET, $_POST, or $_COOKIE.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 19 '06 #4
Kimmo Laine wrote:
"Chuck Anderson" <we************@seemy.sig> kirjoitti
viestissä:U7********************@comcast.com...

I have finally started coding with register_globals off (crowd roars -
yeay!).

This has created a situation that I am not sure how I should handle. I
have scripts (pages) that can receive an input variable from the POST
array (initial entry) or it could be in the GET array (go back and re-edit
a form, for instance.)

In my old sloppy scripting days this was no problem, as I had
register_globals on and would merely access the the input variable by it's
local name (whether it was POST or GET made no difference).

What's the best way to handle this situation where I am not sure if the
input variable is in the GET array or the POST array? My guess is to test
for the presence of the variable (isset, != '') in either array and then
copy it to a local variable from that array.

Is that the best, only, or most efficient way to handle that?


$_REQUEST <-- it contains both $_GET and $_POST variables :)

Well, heck, that's almost too easy. Thanks.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jan 20 '06 #5
Pedro Graca wrote:
Chuck Anderson wrote:

I have finally started coding with register_globals off (crowd roars -
yeay!).


YEAY!
This has created a situation that I am not sure how I should handle. I
have scripts (pages) that can receive an input variable from the POST
array (initial entry) or it could be in the GET array (go back and
re-edit a form, for instance.)


Why is it not POST again?

I'm not definitely sure. I scripted these pages a couple of years ago. I
think it was to provide a look and feel for the user interface I
preferred. A form button to get there to start with and then for some
reason a regular link seemed more appropriate for getting back to the
page. I probably also reused the page/script, but without a form.
Is that the best, only, or most efficient way to handle that?


As Kimmo said you can use the $_REQUEST array which is contains
(almost (*)) all the $_GETs and $_POSTs.

(*) The $_REQUEST array will *not* have duplicate keys from $_GET,
$_POST, and $_COOKIE. There's a configuration value that specifies what
order is followed when PHP builds the $_REQUEST array (default is GPC,
meaning GET, POST, COOKIE).

If you have
$_GET['id'] = 4;
$_POST['id'] = 14;
$_COOKIE['id'] = 77;

$_REQUEST['id'] will be 77.

I never needed to use $_REQUEST and I always know whether the user input
comes from $_GET, $_POST, or $_COOKIE.

Thanks for that extra bit of info. The correct location will be either
POST or GET. They will never both be used.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jan 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randell D. | last post by:
I have a script (below) that can be passed an array and it will dump the contents of the array in to an html table - I use it during development so its nothing sexy. It handles multidimsional...
10
by: Jack | last post by:
How would I add a variable that I will assign to a list of $_POST variables that I extract from a form? My form passes a value for $q. That works fine. What I want to do is run an if/else on it...
6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
2
by: Scott | last post by:
I need to write a function that copies variables to fields. I've used an array and loop because it's neater than writing a similar sentence out 10 times. var myString = new...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
7
by: icosahedron | last post by:
Is there a way to determine if a parameter to a function is a constant (e.g. 2.0f) versus a variable? Is there some way to determine if this is the case? (Say some metaprogramming tip or type...
2
by: assgar | last post by:
I am having problems getting the user selected form info to inserted into the mysql database. I am also rec eving an error: Warning: Variable passed to each() is not an array or object in ...
9
by: Animesh K | last post by:
Hello All: I want to have some re-usable variables, which can be used inside (as well as outside) objects. The use of GLOBALS array is one option, but then I will have to keep track of "reserved...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.