473,655 Members | 3,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable passed in GET or POST array

I have finally started coding with register_global s 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_global s 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 5371


Chuck Anderson wrote:
I have finally started coding with register_global s 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_global s 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_global s 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_global s 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.ber keley.edu/>
Kimmo Laine <an************ *******@gmail.c om.NOSPAM.inval id>
Jan 19 '06 #3
Chuck Anderson wrote:
I have finally started coding with register_global s 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_global s 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_global s 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_glob als 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_global s 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
3513
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 arrays so any element that itself is an array will also be broken down and displayed... Thus... in order to keep track of tables in a multidimensional array, I'm trying to print the name of each array before its displayed... Does anybody know a...
10
2660
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 and assign a new variable based on what was chosen such as if ($q == "red") { $q = "tp"; //change $q to this value $sub = "ak"; //attach this value to the $sub variable } else {
6
2741
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 = server.createobject("scriptlet.typelib").guid guid=Left(guid,instr(guid,"}")) genguid=guid
4
6296
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 the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
2
2798
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 String("id,callername,address,phone,phoneb,email,sqft,source,action,status"); var myFields = myString.split(','); //myValues is an array of values passed to the function var myValues =
23
19167
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
3161
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 trait?) I have a function with an if statement, that I would like to optimize away somehow. I was hoping the compiler would do it for me, but it doesn't seem to. Jay
2
15506
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 D:\web_server\webroot\common_list_process.php on line 1) I can display the contents of the $op array (see below) 2) Am I using the correct loop to unpact the array for inserting into the database?
9
1643
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 variable names" elsewhere. Another option is to declare a $FORALL array in an abstract class and initialize it. And then define every object as an extension of this abstract class.
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8296
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.