Zen Cart Logo
Forums / General Questions / Passing parameters

Passing parameters

Locked

Views: 1,845

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
16 Nov 2006, 11:29 AM
#1
everlastx1 avatar

everlastx1

New Zenner

Join Date:
Oct 2006
Posts:
4
Plugin Contributions:
0

Passing parameters

hello,

I have a stupid question, I dint find an answer yet.
What is the best way to pass parameter from on site to another

for example shopping_cart to checkout_shipping should i do it over post or get and how or should i write it to variable and reed it later?

Don't know what is best practice

thx and Greetings

16 Nov 2006, 3:10 PM
#2
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Passing parameters

You said from "one site to another," as in across two differing domains? If that's the case, step one is to make damn sure you're not passing sensitive material, as both GET and POST will transmit unencrypted.

That being said, both have the same basic function, there are just a few key differences between GET and POST that will typically make the decision for you.

First, GET variables are actually listed in the URL. So if you don't want a long address line, don't use GET. However, having all the variables in the address line makes it very easy to generate a link with necessary accompanying variables, and/or to redirect a page after processing (search for "zen_get_all_get_params" in the Developers Toolkit for examples).

POST variables, on the other hand, are stored in the header contents of the submitted page, so they don't appear in the URL. This makes it a lot cleaner, especially with lots of variables. You can also transmit arrays in POST; not possible with GET.

Downside is that you can't do the simple redirection you can with GET (as they require a standard HTML form and a submission action). It's also tougher to see your variable values at runtime (to see GET just look at the address line, but POST doesn't appear in the HTML source output).

Personally, I like POST, because it makes cleaner URL's and I have developer tools that allow me to look up the POST variables when I'm debugging. But if I have a page where I only ever have one or two variables, I'll use GET just for ease of use and tweaking.

Hope that helps. :smile:

16 Nov 2006, 10:47 PM
#3
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Passing parameters

I have a stupid questionI think this is not a stupid question at all :-) Often it's not easy to decide which one is best to use.

And I agree with BlinSide, of course :-)

Information that you want to store "a little longer" (as long as the session is alive) you can also add to $_SESSION. That way you can pass the data across multiple pages without reposting the data on every page switch.

You can also think about what data you would like to be visible for users ($_GET) or not ($_POST). For example: visitors can bookmark $_GET data, but can't bookmark $_POST data.

note: both $_POST and $_GET paramaters can be manipulated by the user, so you always need to validate the data!

And, don't ask me any numbers, but $_POST also can hold more data than $_GET.

17 Nov 2006, 11:43 AM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,682
Plugin Contributions:
56

Re: Passing parameters

I wasn't sure of your meaning either - did you mean one page on one site to another page on another site? Or one page on one site to another page on the same site. (I'm asking because you referred to shopping cart to checkout shipping, which is normally just a matter of pressing the "checkout" button, and sounds like the latter). For the former, you can embed information in a url; for the latter, look at _SESSION.

Scott

19 Nov 2006, 5:58 PM
#5
everlastx1 avatar

everlastx1

New Zenner

Join Date:
Oct 2006
Posts:
4
Plugin Contributions:
0

Re: Passing parameters

thx guys

this was what I wanted to hear ! :yes:

I stay in the same Domain and decided myself to use the _Session method because it is the easiest way in my case.

19 Nov 2006, 9:26 PM
#6
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Passing parameters

Session definitely has a lot of advantages, you just have to be careful with how you name your variables. You don't want to override any pre-existing variables, and can cause pages to do whacky things to happen on pages where the values are unexpected.

Just keep them on a tight leash and they'll work wonderfully.

19 Nov 2006, 9:59 PM
#7
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Passing parameters

Exactly.

I.e.:

$_SESSION['whateverthemodsnameis']['varname'] = 'varvalue';

This way you only need to rename "whateverthemodsnameis" if it causes conflicts. Which is very unlikely of course, depending on what you use for "whateverthemodsnameis".

20 Nov 2006, 8:34 PM
#8
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Passing parameters

Good point, Paul. That's exactly what I do, I don't know why I didn't think to mention it. Thanks for picking up my slack. :happy: